The scene with the Gravedigger is in the fifth act, first scene, from line 166 to 184 ; this scene strike particulary because it includes both comical and melancholy lements side by side and it’s used to strike all the audience
The actors arrive at Elsinore (II, ii) and immediately Hamlet asks the main actor to recite a melodramatic speech about the killing of Priam of Troy and the despair of his wife Hecuba. After a while, Polonius interrupts him, saying that the speech is too long, but Hamlet makes him continue, then Polonius still interrupts him definitively so Hamlet dismiss them.
The day after ( III, ii ) Hamlet uses them to play “The Mouse-trap” to confirm his suspects about his father’s killer.
The actors are certainly playing parts, but almost everyone watching their performance is playing a part too; they are acting out a “play within the play” before an audience of amateur actors: spies, plotters and hypocrites and probably they think that the play could offence the King and the Queen. And this performance is interrupted too.