Well, the first reasons Hamlet might go mad come not from him but from the situation. By that I mean, his father is dead, which is a shock to the system. His mother remarries, and he actively complains about this; such things cause emotional upset. He sees a ghost, and sighting the supernatural is traditionally hard on the mind. Ophelia promises to avoid him, which isolates him, driving up the stress level. The ghost requires him to take revenge, and that's not in his character.
Hamlet then begins to act oddly, showing all of this stress and perhaps madness. He dresses oddly, with things partially undone. He grabs Ophelia by the wrist, staring at her. He begins to talk oddly, changing his story. Is he playing mad…or really crazy?