This figurative language is a metaphor. Hamlet is comparing Denmark, meaning specifically the castle in Denmark where he is living, to a prison. Hamlet is saying this because he feels trapped and like all of his movements are being watched and analyzed. He feels he is being punished for being emotional about his father's death and scrutinized by everyone around him as one would be in a prison.