Overall, Hamlet is a serious play about Hamlet's revenge of his father's death. In his revenge, many people die along the way, including Ophelia, who was in love with Hamlet. The gravediggers who were digging her grave argued whether or not she should have a proper burial in the churchyard because all indications show that she committed suicide. Their conversation in the play is comedic and many critics believe that a scene like this should not be present in a play as serious as Hamlet. It is humorous because the gravediggers are just going on with their normal day's work and giving each other riddles to solve and singing songs. It is a break from the tension in the rest of the play, and after their short conversation, the play goes back to that tension with Ophelia's funeral. Scenes like this are seen often in Shakespeare's plays. They are known as comic relief and are included to contrast the tragedy of the rest of the plot.
I believe that a scene of comic relief is necessary in a play like Hamlet. It shows that even if something terrible is happening in your life, everyone isn't going to know what's going on and they are going to continue their own lives. The gravediggers don't know that they are talking to Hamlet when he asks who's grave they are digging. Because of this they make jokes about digging their own grave becuase they are the ones actually digging it. In life, not everyone knows your problems and most people have their own problems to take care of. All of the time, people make remarks and jokes about something that they know or have heard about. Someone around them may have personal experiences or problems with that and may have a bad reaction and negative feelings towards that person. In Hamlet, Hamlet questions the gravedigger because he is digging up skulls of people who Hamlet had known, like the jester Yorick. This causes Hamlet to realize that no matter how great you are, even if you were Julius Caesar, eventually everyone turns to nothing but dust.
That is why, in my opinion, the play needed a scene of comic relief. Not only does it relieve tension in the audience, but it also proves that in life what happens to one person doesn't effect the lives of everyone else.