The grave digging scene in Shakespeare's Hamlet serves several dramatic purposes in the play. First, it's about the only comic relief to be found in an otherwise unremittingly heavy, tragic play. The two grave diggers tell a few jokes and their dialogue is full of puns and wordplay. That's the most humor to be found in Hamlet.
The scene also serves to allow a philosophical reflection on life and death--right before most of the actual deaths in the play. These observations serve as a foreshadowing and a contemplation on the brevity of life. The skull of Yorick, the discussion of Alexander the Great, and the discovery that this is the grave of the young Ophelia all serve to remind Hamlet (and therefore us) that life is fleeting, and whatever is gained or achieved here on earth is quickly gone and buried and decomposed. Death is the great equalizer.
The gravedigger's scene marks the return of Hamlet to the play after a long absence. They are digging a grave for Claudius and discuss the nature of kingship and if he will go to heaven. GD1 says that his kingliness will fly up to heaven but his human soul will remain below. They argue over the duty of lowly citizens like themselves. GD1 says they should love their king no matter who he is. GD2 says the king must earn the respect of his subjects. They fight and Hamlet has to separate them. They don't recognise Hamlet and tell him that Claudius is dead. Hamlet holds Claudius's skull and makes his "Alas poor Yorvik" speech. He pays the gravediggers to put Claudius's body in the grave facing down, not up. They used to believe this would guarantee you went to hell. Hamlet ends the scene by meeting Ophelia and telling her that he is sorry. The scene is generally comic and is a light break from the heavier sections of the play.