In Hamlet there is, indeed, a huge amount of spying going on. Rosencrantz and Guildenstern are tasked with spying on Hamlet for Claudius and Gertrude. Polonius has Reynaldo check on Laertes. Claudius and Polonius set up the encounter between Hamlet and Ophelia in order to spy on them. Polonius spies on Hamlet (with fatal results for himself) when Hamlet is with his mother. The Ghost can be said to spy on Hamlet, intervening and telling him to leave his mother alone. In the previous scene, Hamlet spies on Claudius as Claudius is praying, with the intent to kill him. As Ophelia’s funeral is taking place, Hamlet and Horatio are, in effect, spying on the mourners before Hamlet steps forward and challenges Laertes.
The significance of this pattern is that, basically, nobody trusts anyone else at court. They are all at each others’s throats with secrets of their own and hidden agendas, guilt, and repressed anger. Claudius, with murder on his hands, is the worst. He knows Hamlet is on to him and therefore must have him watched. Polonius, though usually portrayed as a doddering old man, is also a kind of guilty father. He knows his children are both troubled for different reasons, and he also fears (justifiably so) that his daughter has become Hamlet’s mistress. Hamlet’s plotting is carried out in secret and he must surreptitiously judge the reaction of Claudius and others to his schemes for revenge.
The play as a whole is a nightmare of family misery and blood-soaked retribution. “Spying” in itself may be one of the milder things taking place, but nonetheless part of the harshly realistic power struggle within the royal family of medieval Denmark.