It is very hard not to feel sorry for Hamlet in lots of ways, though equally we might argue that he has acted disproportionately to the situation that he faces. However, let us consider what has just happened. Hamlet, doubting the veracity of the Ghost's words, organised a special "Mousetrap" to see once and for all if what the Ghost said was true. It is clear that one of the challenges he faced in the earlier Acts was whether to believe the ghost or not. The "Mousetrap", of course, was a splendid success in establishing the guilt of Claudius. Having his proof, Hamlet went on to challenge his mother with the truth and to condemn her according to the Ghost's wishes. Of course, this tragically ended in the mistaken killing of Polonius.
As he leaves at the end of Act III, Hamlet knows he is facing a very difficult and perilous situation. He has just killed the King's advisor, and now Claudius knows that Hamlet knows the truth of how Hamlet's father really died. He is therefore a threat. Note how he talks of his two fellow companions on the journey to England, Rosencrantz and Guildenstern:
There's letters seal'd, and my two school-fellows,
Whom I will trust as i will adders fang'd,
They bear the mandate, they must sweep my way
And marshal me to knavery...
Hamlet's immediate challenge therefore is how to resolve this situation and ensure that he survives the trip to England and is able to return to Denmark and revenge his father in the way that he has put off for so long before this point in the play.