All of this activity at the start of Act 4 is part of Hamlet's acting crazy. He must maintain this act, especially now that he has slain the chief advisor to King Claudius. He knows that his actions have made his position at Elsinore even more vulnerable because now the King has more reason to be concerned about what Hamlet might do next. When Claudius first hears what happened, his immediate response is something like, "it would have been me if I had been there." Hamlet's craziness was a problem; Hamlet's knowing what Claudius did to King Hamlet is threatening; his murder of someone in the castle is terrifying to Claudius. Claudius knows that he must act decisively and send Hamlet, not only to England, but to his death in England, or everything Claudius gained could be lost.
Hamlet's stashing the body and his taunting of Rosencrantz and Guildenstern and later Claudius also serves a comic relief coming immediately after the heaviness of the end of Act 3 with all that was discussed with Gertrude in her room. We see that Hamlet hasn't lost his wit and he is still on track to do what he needs to do in order to exact his revenge on Claudius. There are several fun puns and potty humor-type jokes in the scene, but we also see the menace and malice in both Claudius and Hamlet. We are anxious to see what happens next in this "battle of the wills."