Hamlet warns that he may take up an eccentric conduct and says, more than once, that he is not mad. But the court does not know this and takes him to be truly mad, lovesick, or dangerous.
In Act I, scene 5, after hearing the ghost, he asks his friends to swear never to reveal that they know anything, "However strange or odd I bear myself," because "henceforth" he may find it convenient to put on an eccentric conduct. In Act II, scene 1, Ophelia tells her father that the prince appeared disheveled, and Polonius asks: "Mad for your love?" Hamlet tells Rosencrantz and Guildenstern, in Act II, scene 2: "I am only mad to the north-northwest. When the wind is southerly, I can tell a hawk from a heron."
In Act III, scene 1, Claudius sees Hamlet with Ophelia and concludes: "Love? His feelings do not tend that way." To the king, something in his soul is brooding over melancholy. In the queen's chamber, Gertrude does not see the ghost and concludes "Oh, he is mad." Hamlet answers that he is not mad and says that he is essentially not mad, but mad by cunning.
In Act IV, scene 1, Gertrude tells the king that Hamlet killed Polonius and describes him as "mad as the sea and the wind." In Act V, scene 2, asking Laertes's pardon, Hamlet attributes the offense to madness: "His madness is poor Hamlet's enemy."