What is the importance of death in Hamlet and the graveyard scene?
Death. It's enough to drive a prince crazy.
In Act V, scene i of Hamlet, after the suicide of Ophelia and before the bloodbath in the final scene, Shakespeare uses the comic relief of the gravediggers to layer his penultimate scene with gothic imagery, morbid jokes, and black humor.
Enotes says it best:
Death, decay, and the futility of life fill the spoken thoughts the Danish prince, and the appearance of Ur-Hamlet's tortured ghost leaves us with cold comfort about the afterlife. Shakespeare skillfully shows vitality being cut short and leading to a gruesome end. Thus, in the graveyard scene that opens Act V, Hamlet holds up the skull of a court jester he knew as a boy, and utters the lines,
Alas, poor Yorick! I knew him, Horatio: a fellow
of infinite jest, of most excellent fancy: he hath
borne me on his back a thousand times; and now,
how abhorred in my imagination it is!
Not only is death pervasive, its occurrence is a product of chance and circumstance. True, Hamlet anticipates his death, while Claudius and, perhaps, Laertes deserve theirs, but Polonius dies by accident as does the Queen, while Ophelia's suicide seems to be beyond her control. Life inevitably yields death and a wormy grave, and its occurrence cannot be foreseen or avoided.
The play begins and ends with death. Hamlet is visited by his dead father in Act I, and here in Act V he visits two dead friends, Yorick and Ophelia. All of their deaths were off-stage as we prepare for the on-stage deaths of Hamlet, Gertrude, Claudius, and Laertes. By the end, the entire cast is laid to rest. This is the realization that Hamlet must accept: the inevitability of death, "the undiscovered country, from whose bourn no traveller returns."
Hamlet is prepared for death prior to this scene. He tells Horatio:
If it be now, 'tis not to come; if it be not to come, it will be now; if it be not now, yet it will come: the readiness is all.
Only until Hamlet is ready to die will he be able to fulfill his duty as heroic avenger.
First, we see that even in death there are lies. Ophelia did not die in a "Christian" manner. She cut her own life short, but because of her status she is allowed a Christian burial. The gravedigger says it best when he says,
Why, there thou sayst. And the more pity that great folk should have countenance in this world to drown or hang themselves more than their even Christian.
Only the gravediggers, however, acknowledge this discrepancy. Hamlet and Laertes argue over who loves her more and even go as far as to wrestle with each other over her grave.
Next, we see the flippancy with which death is treated. Shakespeare used his gravedigger character for comic relief and in doing so also pointed out the irreverence with which death was treated. Hamlet points out this behavior when he talks about how the gravedigger is treating the skulls saying,
That skull had a tongue in it and could sing once. How the knave jowls it to the ground, as if it were Cain’s jawbone, that did the first murder! It might be the pate of a politician, which this ass now o'erreaches, one that would circumvent God, might it not?
Hamlet also says that only the rich are able to afford to be sensitive about death. He points out the irony that these once powerful people are now merely skulls rotting in the graveyard to be battered and broken, the objects of crude jokes by the gravediggers.
Death is the final irony to all the machinations of the Danish court, for it is the only solution to correcting the problem of what is "rotten in Denmark." The final act is an ending worthy of one of the great mafia families as Hamlet, Prince of Denmark, "takes care of all family business." And, he leaves his country in the care of the noble Fortinbras.
The graveyard scene, while providing some comic relief, also presages the death of the court as the gravediggers make gruesome jokes about the brevity of life while they continue to mention how man is mortal, no matter how noble, returning to the dust from which he came.
In an ironic twist, dying becomes the most noble deed that Claudius, Polonius, and the other corrupt courtiers enact. So, Hamlet, in the words of Ernest Johnson,
disentangles himself from the temptation to wreak justice for the wrong reasons and in evil passions, and to do what he must do for the pure sake of justice....from that dilemma of wrong feelings and right actions, he ultimately emerges, solving the problem by attaining the proper state of mind.
In his struggle to act morally within such a corrupt world while maintaining his integrity, Hamlet is a "man for all seasons" and dies redeemed, rather than condemned.