Hamlet was a play written about betrayal and deception. Hamlet is trying to collect evidence against Claudius. To try to deceive him, Hamlet fakes being crazy.
In an effort to prove Claudius' guilt, Hamlet stages a play for Claudius and his mother to watch: the murder of Gonzago (The Mousetrap). He wanted to gauge Claudius' reaction during the murder scene.
Claudius' reaction during the scene where the king is murdered was uncomfortable, once he knew what they play was about and said that he needed "some air".