Much of the humor throughout Hamlet is accomplished only through live performance. A director working with a group of actors can bring out the humor.
The recent Royal Shakespeare Company Production of Hamlet (2008) with David Tennant and Patrick Stewart directed by Gregory Doran is a wonderful example. In 2010, PBS aired it on "Great Performances". This version is available to watch at the PBS website. (See the link below.)
In this production, the "mad" Hamlet mocks both Polonius and Claudius. Tennent also used his body effectively to bring out the humor in the play. The reactions of both Claudius (Patrick Stewart) and Polonius (Oliver Ford-Davies) were also important in eliciting laughter from the audience.
Shakespeare often interjected humor into his tragedies which, of course, heightened the tragic actions.
As an actor in Kevin Klein's Hamlet told me, "Play comedy for tragedy and tragedy for comedy."
Below is the link to PBS>
www.pbs.org/wnet/gperf/episodes/hamlet/watch-the-film/980/ - Cached
I would call the humor a bit morbid, since one of the Gravediggers and Hamlet are making fun of how long it takes certain bodies to decompose (based upon their occupation in life) versus others.
Also, because the Gravediggers are also called Clowns, there is to be expected a sense of both of them being "bumpkins" who create humor through misuse of language and some physical comedy. We don't have exact stage directions, but if you give two clowns each a shovel, I am sure they could find a way to create physical comedy. They quote Scripture and debate the correctness of Ophelia receiving a Christian burial, and humor comes from the ignorant logic they employ.
Overall, this scene, in the midst of a Tragedy, is called comic relief, meaning that, for a moment or two it relieves the tension that is building in the dramatic plot and allows the audience to "blow off some steam" through laughter.