As Claudius explains to Laertes, there are two main reasons he can't really punish Hamlet. The first is that Hamlet's mother dotes on her son so much that it would kill her if something happened to him. The second reason is that the people love Hamlet and might revolt against Claudius if Hamlet was imprisoned. In addition, Hamlet is the heir to the throne, a choice Claudius himself made at the beginning of the play. Locking up the heir that he named would make both Claudius and Hamlet lose face. In addition, Hamlet does have royal blood and Polonius was simply an advisor to the king. In an age of the divine right of kings, this would seem an insult to the office of the king himself, because Hamlet completely outranked Polonius. Finally, Polonius was hiding behind the curtain in Hamlet's mother's bedroom when he was killed so it would be easy for Hamlet to mount a defense that he was simply protecting the Queen.