Dramatic irony is a device that is used to cause a dramatic effect on the audience, it may be used for comic purposes or to make the audience accomplice of specific actions. Dramatic irony takes place when the audience is aware of something that the characters are not.
In Hamlet, there is a play being performed for the court, this play is directed by Prince Hamlet with the objective of discovering whether his uncle actually murdered his father or not. This play represents exactly everything that Hamlet believes, so the queen in the play represents her actual mother, Queen Gertrude. As a result, when Gertrude comments on the play and she says "The lady protests too much, methinks", she is actually criticizing herself; she is not aware of that, but Hamlet and the audience know this. The employment of dramatic irony here is intended to produce laughter and make the audience an accomplice of Hamlet's plan. Hamlet was very critical of her mother, because he re married too soon after the death of his father.