The first answer to this question is excellent and quite thorough. I would just add that the existential nature of the graveyard scene also contributes to our understanding of Hamlet's character. In this scene, he is once again contemplating the meaning of life, as he has in prior soliloquies (most significantly in "To be or not to be") and also in his scene with Claudius when he is being questioned as to the whereabouts of Polonius's body. In that scene, and in this graveyard scene, Hamlet seems intrigued by the thought of humans returning to the ashes from whence they came. He philosophizes on why we all try so hard in life, why we put forth any effort at all if death is indeed the great equalizer. (He refers to how Alexander the Great may just be serving to mend a mud wall.) This adds to our understanding of Hamlet's character because he is still asking himself what his purpose is, whether he should indeed take action, whether any of it will make a difference.
That's a complicated question and I fear I can only touch on part of it. For one, it shows that the common man (non- royalty) is aware of Hamlet's madness as the Grave Digger and the clown discuss Hamlet's madness. That opens up a whole other can of worms. What happens when madness goes public? In a noble, that's bad, but in a fool, who is to say? Yorick was the King's jester, a sacred fool; perhaps the only person in a king's court who could act mad and suffer no reprecussions. In a member of the royal family the consequences are far more dire.
But that's from a literary perspective; a perspective that has all the time in the world to dwell over the scene and break it down line by line. I think it plays very differently in front of an audience. We get some much needed comedy, not only from the two grave diggers but from Hamlet as well. We get Hamlet conversing with a skull which may lead us to believe he's really mad, and finally we get him fighting with Laertes in a rage. That serves the purpose of finally confirming for us that he truly loved Ophelia, because consider the circumstances in which they last met. It also gives Laertes further cause for hating Hamlet. And finally, it may lead to a further clouding of Hamlet's reason as far as the audience goes.
Another thing that strikes me in this scene is that the Gravedigger also acts mad in his own way and uses word-play the same way that Hamlet does when dealing with the likes of Polonius and Rosencrants and Guildenstern. Again, it gets a pass with the lay-man, but not with the nobility.
Finally he gets in the fight with Laertes. This is one of the few moments in the play where I believe Hamlet is actually mad as opposed to feigning lunacy. The other places being where he decides to go with the ghost, when he kills Polonius, when he confonts his mother, when he confronts Ophelia and when he finally kills Claudius. And I don't mean mad as in he's crazy, but as in he's enraged; he's lost his reason. Note the difference between how he speaks in the fight and where he's feigning madness. He's not playing with words here, his language is visceral.
Finally we're confronted with real madness. We see the end-result of Ophelia's lunacy. She ends up dead. I don't believe she committed suicide, as I don't believe a person not in their right mind can make that decision, but dead she ends just the same. And there are consequences to that just as there are to lunacy.