Hamlet feels insignificant in his life, and is overwhelmed with the utter baseness of the death and decay he sees.
The scene opens with the clowns discussing whether or not Ophelia is entitled to be buried on consecrated ground (because she was a suicide she should have been relegated to a different section). This suggests that where our bodies lay matters. Yet the rest of the scene shows it does not, for even in consecrated ground, the bodies are disturbed and treated with irreverance.
Hamlet is disturbed by the clowns' light-heartedness as they sing and toss skulls about. He looks into the graves and thinks of the people the dead might have been--a lawyer, a politician, a land-owner, even a great leader. The clowns have unearthed the stinking skull of the jester, Yorrik (see Jamie's quote), who used to be full of life and humour, and he realizes that we come to nothing when we die. Our skulls could be tossed about by singing gravediggers. Even the bodies of great men like Alexander or Caesar would eventually turn to dust and then to dirt. He says Alexander might have turned to loam that could be used to stop a beer keg. As for Caesar, he might be used to stop up a hole to keep the draft out:
Imperious Caesar, dead and turn'd to clay,
Might stop a hole to keep the wind away:
O, that that earth, which kept the world in awe,
Should patch a wall to expel the winter flaw!
We have no protection against the indignities of death. Life will take it all and who we were won't matter.
Hamlet contemplates mortality and life's short meaning as he contemplates Yorick's skull. The gravediggers have unearthed the remains of the young man's former friend. They have little regard for the dead man who once was of great importance to Hamlet. Holding the skull, Hamlet muses in 5.1.190-202:
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! my gorge rims at
it. Here hung those lips that I have kissed I know
not how oft. Where be your gibes now? your
gambols? your songs? your flashes of merriment,
that were wont to set the table on a roar? Not one
now, to mock your own grinning? quite chap-fallen?
Now get you to my lady's chamber, and tell her, let
her paint an inch thick, to this favour she must
come; make her laugh at that."