Shakespeare relies on soliloquies because how else would we know what is happening in Hamlet's head. Sure, he could have written in a part for an omniscient narrator who could have told us all about it, but the connection is lost between character and reader or watcher of the play. The soliloquy is how we connect with Hamlet. It is what makes the play so unbelievably brilliant because we feel we are experiencing all of Hamlet's turmoil and grief right along with him. The play would not have been nearly the success, if a success at all without the critical connection that we get to have with Hamlet. It bring the play to life when we feel we are a part of it. Through the use of soliloquies we feel as though we are Hamlet's confidants that he is confiding in us his innermost feelings.
Because plays are plays, and not novels, Shakespeare relies on soliloquies in all of his plays to let his audience know what the characters are thinking. Otherwise, we would just have a lot of one-dimensional characterizations happening on stage - or we would only be able to guess as to why the characters are doing and saying things. Soliloquies provide the characters' thoughts to the audience so that people watching (or reading) can know what is happening in their heads.
With regards to Hamlet, soliloquies are critical to understanding the confusion and torment going on within Hamlet himself. If we only had his reactions with the other characters to go on, we would have no clue as to why he's behaving the way he is. We may not always agree with what he does and says, but at least we have heard his thoughts to understand where he's coming from.