In Act 4 Scene 2 of Hamlet, what is Shakespeare's intention in creating such play of words at this point?
Let us just remind ourselves what Hamlet has just done. He has killed Polonius, thinking him to be Claudius, and now is pursued by two people whom he thought to be his friends, but are obviously at this stage in the play more loyal to Claudius than to him. Perhaps this is why we can see Hamlet engaging in such biting humour during this scene. He uses puns to show what he really thinks of these "friends" of his, by saying, in response to Rosencrantz asking if Hamlet believes he is a sponge:
Ay sir, that soaks up the King's countenance, his rewards, his authorities.
Hamlet is betrayed on all sides in this play, and by those whom he had thought he could trust. His biting word play reveals just how let down he is by Rosencrantz and Guildenstern.
However, equally, we could say that this scene is included to present Hamlet as almost an anti-hero. As he leaves the scene as if he were playing hide and seek, we begin to think that the madness he has put on might actually be real after all. His lack of contrition and guilt do nothing to endear him to us, and we therefore question his heroic status.