"The Mousetrap" is the means by which Hamlet obtains the proof he needs to verify the Ghost's claim that Claudius is a murderer. The play-within-a-play literally traps Claudius because the king's reaction reveals his guilt.
This scene is one of many references to traps and snares in the play as a whole. Polonius warns Ophelia that Hamlet's "tenders of affection" are "springes [snares] to catch woodcocks" (1.3.124). To thwart Rosencrantz and Guildenstern, Hamlet tells Gertrude, "'tis the sport to have the enginer/ Hoist with his own petard" (3.4.229-230), meaning that one who makes bombs may be blown up by them. He will switch letters with the pair so that they will deliver a letter ensuring their own doom rather than Hamlet's.