This is a turning point for Hamlet in this play--he decides to play the madman, hoping that he'll discover something about his father's murderer. Shakespeare changes Hamlet's language to show that he's now changed--he won't appear to others to be "himself" or at least the self he used to be. Hopefully, by not being himself, others will treat him differently, perhaps being less cautious about what they say or how they treat the madman. Remember that in Shakespeare's time, "madmen" were assumed to have no sense at all.
Shakespeare uses prose for specific reasons: to denote madness, to mark a character who is of a low station in life, in letters, etc. In Act 2, sc. 2, when Hamlet is talking with Polonius, the prose serves two purposes. First, it helps to make Hamlet appear mad, and second, it shows Hamlet's contempt for Polonius by treating Polonius like he is lowly. When Hamlet is talking with the players, he talks in prose, possibly, to attempt to be on their level because he is a gracious host. Throughout the play, whenever Hamlet wants to seem mad, he speaks in prose.