Mr. Wopsle provides comic relief in a terrible performance of Hamlet.
Comic relief is the use of humor to lighten up otherwise dramatic events. Pip's life in London is full of intrigue, with secret benefactors, stern lawyers and enigmatic clerks, and pining for Estella. It's nice to take a chapter for some complete nonsense.
Mr. Wopsle thinks that he is an actor, or wants to be an actor, but he is not very good. The reason Pip’s visit to the theater to see Wopsle perform Hamlet is so funny is partly because of the way Pip describes it and partly because of how rudely the audience treats the actors. Granted, it is not appropriate to be rude in a theater. However, the description is funny as well as kind of sad.
Hamlet is one of the most popular Shakespeare plays, and is usually treated with great respect. This is a terrible production, and neither actors nor audience are taking it seriously. Therefore, a highly serious and dramatic play turns into a farce.
For example, during the famous “To be or not to be” soliloquy, the audience taunts Hamlet nonstop.
Whenever that undecided Prince had to ask a question or state a doubt, the public helped him out with it. As for example; on the question whether 'twas nobler in the mind to suffer, some roared yes, and some no, and some inclining to both opinions said "Toss up for it;" and quite a Debating Society arose. (Ch. 31)
The audience teases Wopsle mercilessly for every little thing that he does, but he makes it easy on them. For example, after “moralizing” over the skull in the churchyard scene, Wopsle wipes his fingers on a handkerchief. That gets the audience in stitches.
Even Pip, who is generally a gentle soul, can’t avoid sharing in Wopsle’s misery.
We had made some pale efforts in the beginning to applaud Mr. Wopsle; but they were too hopeless to be persisted in. Therefore we had sat, feeling keenly for him, but laughing, nevertheless, from ear to ear. (Ch. 31)
After the play, Pip learns that Wopsle has been using the name “Waldengarver,” and the indignity continues when the costume is unceremoniously stripped off of him. Wopsle asks how it went, and Pip answers, “Capitally.” This lie, intended to make Wopsle feel better, is funny in itself.