Refer to Act 3, Scene 3, beginning with line 27. Hamlet's mother has sent for her son to berate him for causing the uproar at the play-within-a-play and serioiusly offending her new husband King Claudius. With the King's approval, Polonius intends to hide behind the arras (tapestry) to eavesdrop on the interview between the Queen and Hamlet. Polonius tells Claudius: "'Tis meet that some more audience than a mother/ (Since nature makes them partial) should o'erhear/The speech of vantage." Claudius probably hopes Polonius will learn some valuable information, such as whether Hamlet knows anything about his murder of his brother King Hamlet, or whether Gertrude and Hamlet might be plotting against him.
Refer to Act 3, Scene 4, lines 19-24. Hamlet's aggressive behavior frightens the Queen, who thinks he is mad. She cries: "What wilt thou do? thou wilt not murder me? Help, ho!"
Out of loyalty to the Queen, the hidden Polonius cries, "What, ho! Help, help, help!"
Hamlet draws his sword and thrusts it through the arras without knowing who is hiding there. He may, as he tells his mother, have thought it was Claudius himself. He may have suspected that he had walked into a trap. There has been much speculation over the centuries about Hamlet's motivation, but he obviously doesn't like having two people calling for the palace guards. He probably thinks he will end up in a dungeon if his mother really believes he planned to murder her and there is a witness who will support her accusation. If he is imprisoned, Claudius will have an excellent opportunity to have him killed.
The simple answer to your question is that Polonius got himself killed by calling, "What, ho! Help, help, help!" instead of just remaining in hiding. Hamlet says to the old man he has just killed: "Thou wretched, rash, intruding fool, farewell!"