It's because Hamlet was not intending to kill Polonius. Polonius is hiding behind the curtain when Hamlet is talking to his mother Gertrude. Gertrude is telling Hamlet that he has offended "his father" very much. He replies that SHE has offended his father very much. She is talking about Claudius, who is her husband, but not Hamlet's father (Hamlet's uncle), but HE is talking about his father, whom Claudius killed and then married Gertrude. Gertrude is trying to find out why Hamlet is so depressed, so she decides to talk to him. Polonius is in on the plan and was going to hide behind the curtain to see what Hamlet said, because they both think it might have something to do with Polonius' daughter, Ophelia, who Hamlet was supposed to be in love with. Hamlet has recently treated Ophelia rather shabbily.
When Hamlet sees the curtain move, he thinks it is the king eavesdropping, and stabs him, realizing too late that it is not the king, but Polonius.
Hamlet goes to see his mother because Polonius tells him she has sent for him. Hamlet doesn’t like or trust Polonius to begin with. He doesn’t know why his mother wants to see him. Gertrude already suspects that her son is mad. The interview gets off to a bad start. Hamlet finally says:
You are the queen, your husband’s brother’s wife;
And—would it were not so—you are my mother.
Nay, then, I’ll set those to you that can speak.
My edition of Hamlet footnotes this as meaning “I’ll have you dealt with by those in authority.”
But Hamlet lays hands on her to prevent her from rising and says:
You go not till I set you up a glass
Where you may see the inmost part of you.
These lines are extremely important. He is speaking metaphorically, of course, but Gertrude, who already thinks her son is a lunatic, takes him literally. She thinks he plans to use his sword to cut her open and display her vital organs to her. She says:
What wilt thou do? Thou wilt not murder me?
And immediately Polonius, who is hiding behind the arras and cannot see anything, thinks Hamlet is murdering his mother. He cries:
What, ho! Help, help, help!
Hamlet didn’t know why he was summoned here. He is confused and alarmed, with a woman (who might have been implicated in his father's murder) screaming for help in front of him and a hidden man shouting for help behind him. He thinks he has walked into a trap. He doesn’t want to be arrested by the guards because he might never get free again. He could end up in a dungeon. His own mother might not even try to help him. He would be at the King’s mercy. Claudius might have him killed. He draws his sword and stabs the unknown man behind the arras, who turns out to be Polonius. Then he proceeds to express his pent up rage and disgust to his mother, metaphorically setting up a glass for her to see the inmost part of herself. And his words are effective. She says:
O Hamlet, speak no more.
Thou turn’st mine eyes into my very soul,
And there I see such black and grained spots
As will not leave their tinct.
It is very simple as the character of hamlet is a round one so he developes through the action of the play.after the "Mouse-Trap" play Hamlet became sure that claudius is the killer of his father and he delayed his revenge because claudius was praying and he can not just send him right away to heaven so he waited.But in the bedchamber scene Hamlet figured out that the man behind the tapestry is claudius as who else would be in the queen's room at that late hour than her own husband.So he made his mind quiekly and seized this golden opportunity to avenge his father.