Spying is an interesting theme in William Shakespeare's Hamlet because so many of the characters are engaged in it.
By far the worst offender is Polonius. He is the king's right-hand man, so we assume he has had some practice at it and perhaps some need for it. However, he spies even on his own children. Polonius sends Reynaldo, his servant, to spy on his son, Laertes, while Laertes is away at college. Even worse, he tells Reynaldo that he is free to spread some lies about Laertes as long as they help him discover the truth.
Polonius and Claudius both spy on Hamlet and Ophelia:
At such a time I'll loose my daughter to him:
Be you and I behind an arras then;
Mark the encounter: if he love her not
And be not from his reason fall'n thereon,
Let me be no assistant for a state,
But keep a farm and carters.
He rather stakes his life and livelihood and this one spying incident. In a final rather ironic act, Polonius dies while he is hiding behind the tapestry in Gertrude's bedroom, spying again on Hamlet. His obsession with spying got him killed.
Horatio's spying is rather harmless. He acts as Hamlet's spy when he watches for Claudius to react during the play and even when he is called in to verify the existence of the ghost before anyone tells Hamlet about it.
Rosencrantz and Guildenstern are both spies for Claudius and Gertrude, though they are particularly bad at it. Their spying also gets them killed.
There is also an element of spying with Fortinbras, as he prepares to fight Denmark and lies to his uncle about it.
Even the Ghost appears in Gertrude's bedroom, presumably spying on how things are going between his wife and son.
Claudius is the king, and it should be beneath him to do his spying himself, yet he does. He and Polonius spy on Hamlet and Ophelia. Claudius also asks Hamlet's friends Rosencrantz and Guildenstern to spy on Hamlet, and, by the way, Gertrude consents to both of these spying episodes on her own son.
Hamlet does not spend much of his time spying. He and Horatio do spy first on the gravediggers and then on Ophelia's wedding, but theirs is a different sort than Polonius's. Hamlet also spies on Claudius after the play, when he finds him at confession. Again, this is a bit less devious than some of the other forms of spting in this play.
The physical act of spying simply underscores the element of lies and deceit in this play. Really, the only one who really tells the truth all the time is Horatio; it is probably not a coincidence that he is virtually the only to survive the carnage of the final scene.