In modern metaphorical sense, we can say that Hamlet thinks of Polonius as a rat, who is the spy for Claudius. Hamlet kills Polonius mistakenly thinking King is hiding behind Queen’s room. King has realized that Hamlet deducted that he is the killer of his father, therefore sends Polonius to spy on him. Hamlet appears storming down screaming his mother name. Polonius hides behind the wall, intending to secretly heat the conversation and report it to King. The Queen gets terrified that her son is going to kill her, and cries out for help. Foolishly, Polonius also cries for help and Hamlet thinks King is chasing him and kills Polonius. This is why Hamlet calls him rat.
What is the meaning of “How now, a rat? Dead! For a ducat, dead!?”