There is no evidence that Hamlet was insane.
Was he depressed by the death of his father? Sure. Angry at the hasty marriage of his mother to his uncle? Why not. Shocked and horrified by what the ghost tells him about the murder? No doubt. Upset at his girlfriend, Ophelia, for being used by her father, Polonius? Yes. Disgusted by his mother's shallowness and sexuality? Absolutely. Overwhelmed by the task of revenge given to him? Unquestionably.
Actually, considering all of what Hamlet has to deal with, he does pretty well. Nothing in his behavior would suggest insanity. There is no question, in his effort to annoy and sting and expose the guilt of the King, Hamlet acts insane, but this is but part of his plan to "catch the conscience of the King."
Furthermore, no one really thinks Hamlet is insane. Even Polonius, who's not all that swift, says "Though this be madness, yet there is a method in't.—" Madness for a reason is hardly madness.
And here's Hamlet, himself, on the subject: "I am but mad north-north-west. When the wind is southerly I know a hawk from a handsaw."
So, Hamlet, when it suits him, may act insane (and he's very fond of the craft of acting), but he's not insane.
Hamlet feigns madness in a clever plot to conceal his true intentions and feelings toward Claudius and his mother. Hamlet’s madness is never really proven nor is it disapproved through-out the play. His ambiguity in nature is what makes him such a complex character. Hamlet was experiencing rage and severe anger which leads one to be aware that he was experiencing a psychological impact following his father's murder, but that does not make him mad. Hamlet is aware that if he fakes being mad that he will confuse Claudius. Claudius will not sense him as a threat for the throne.