At the beginning of act 3, scene 4 of Hamlet, Queen Gertrude almost certainly believes that her son, Hamlet, has gone mad. His behavior has been so erratic and his speech so strange that anyone would think so. This is why she allows Polonius to spy on her meeting with her son. Gertrude is to be harsh with Hamlet and try to discover the reasons behind his madness.
As the scene continues, Hamlet makes no secret of what he thinks of Gertrude's actions. His near violence frightens Gertrude, perhaps convincing her further that her son has gone crazy. Polonius, hidden behind a curtain, cries for help, and Hamlet, thinking the spy is Claudius, stabs him. Gertrude is bewildered and horrified by what has happened.
Hamlet, however, does not let up on Gertrude. He makes her see her hypocrisy and her sin all the more clearly. What she has done, he implies, is real madness. Her passions have overtaken her. She has married her dead husband's brother. Gertrude does not want to hear more. Hamlet's words are “like daggers,” and they make her see the state of her soul. No insane person could speak in this way, and Gertrude likely no longer thinks her son to be mad.
Then the ghost of Hamlet's father appears, and Hamlet speaks to him. Gertrude, though, cannot see or hear the ghost, and once again, she questions her son's sanity as she witnesses Hamlet talking to empty air. Hamlet assures his mother that he is not crazy. His madness is only an act that he is using to exact his revenge. Gertrude promises not to tell Claudius. At this point, the audience does not know for sure whether Gertrude is convinced by Hamlet's words or not. He is certainly speaking sanely enough at this point, yet the image of him speaking to “nothing” must remain in Gertrude's mind. Still, she agrees to do as Hamlet says.