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.