The beginning of Act 5 is the best place to how comic elements actually heighten the tragedy of the play. At the start of Act 5 two grave diggers are joking around as they prepare what we know is going to Ophelia's grave. Hamlet is at first disturbed by their joking and seeming irreverance for the job, but realizes that even grave-digging could become a "habit" that becomes common. Once Hamlet starts talking to the grave digger there are lots of jokes about the ownership of the grave and what happens when people die. All of this conversation just lays heavy on us as audience members though because even though we are laughing, we know that the "other foot is going to fall" when Hamlet realizes that Ophelia is dead. In fact, the mood changes pretty quickly when Hamlet finds himself holding Yorick's skull -- the skull of the court jester who he knew so well as a child. All of a sudden, death isn't just a theory, it is very REAL. Hamlet realizes that no matter what you were in life, when you are dead you are ashes. It is a rather sobering thought.
Death becomes even more real and more devastating when seeing Ophelia's funeral procession and Laertes' show of grief. The comedic elements of a few minutes ago are long gone when Hamlet makes his bold proclamations of love and grief over Ophelia. The tragedy is certainly heighten by the juxtaposition of conversations in this scene.