After Hamlet sees the ghost of his father in act 1, scene 5 of Shakespeare's Hamlet, Hamlet tells Horatio and Marcellus that he intends "To put an antic disposition on" (1.5.192). The common interpretations of that line is that Hamlet is going to feign madness, although Hamlet gives no reason at the time for doing so, and how he subsequently behaves, as Claudius says, "Was not like madness" (3.1.173).
It's possible that Horatio plants the "antic disposition" idea in Hamlet's mind a scene earlier, in act 1, scene 4, when the ghost of Hamlet's father first appears to Hamlet, and motions for Hamlet to follow him away from Horatio and Marcellus.
Horatio warns Hamlet against following the ghost.
HORATIO. What if it tempt you toward the flood, my lord,
Or to the dreadful summit of the cliff
That beetles o'er his base into the sea,
And there assume some other horrible form,
Which might deprive your sovereignty of reason
And draw you into madness? (1.4.75–80)
Nevertheless, Hamlet's decision to "put an antic disposition on" seems like an afterthought which occurs to him after he's made Horatio and Marcellus swear, five times—three of those times with the help of the ghost crying out "Swear!" from under the earth—not to reveal that they've seen the ghost of Hamlet's father.
HAMLET. But come!
Here, as before, never, so help you mercy,
How strange or odd soe'er I bear myself—
As I perchance hereafter shall think meet
To put an antic disposition on—
That you, at such times seeing me, never shall,
That you know aught of me; this is not to do (1.5.188–199)
Elsewhere in his plays, Shakespeare uses the word "antic" to mean "foolish," not "mad." Hamlet never uses the word "antic" again after act 1, scene 5, and he also makes no mention of madness until later in the play, in act 2, scene 2, in his conversation with Rosencrantz and Guildenstern.
HAMLET. I am but mad north-north-west. When the wind is
southerly I know a hawk from a handsaw (2.2.376–377).
Hamlet's first attempt to put on an "antic disposition," as described in detail by Ophelia to Polonius in act 2, scene 1, certainly appears more foolish than mad.
OPHELIA. My lord, as I was sewing in my closet,
Lord Hamlet, with his doublet all unbraced,
No hat upon his head, his stockings fouled,
Ungartered, and down-gyved to his ankle;
Pale as his shirt, his knees knocking each other,
And with a look so piteous in purport
As if he had been loosed out of hell (2.1.87–93)
Amleth, Prince of Denmark, from the twelfth-century book of Danish history, Gesta Danorum, by Saxo Grammaticus—one of Shakespeare's sources for Hamlet—provides a historical frame of reference for Hamlet's "antic disposition."
Amleth beheld all this [his uncle, Feng, murdered his father to become King, and married Amleth's mother, Gurutha], but feared lest too shrewd a behavior might make his uncle suspect him. So he chose to feign dullness, and pretend an utter lack of wits. This cunning course not only concealed his intelligence but ensured his safety (Gesta Danorum, book 3).
Amleth doesn't trust that Feng won't murder him for knowing or suspecting what Feng has done, so Amleth pretends to be a fool in order to lead his uncle to believe that Amleth is no threat to him.
Grammaticus writes that nobody really believes that Amleth is truly a foolish imbecile, which is paralleled in Shakespeare's Hamlet. Claudius doesn't truly believe that Hamlet is mad, even though Polonius insists that he knows the reason for Hamlet's madness—"This is the very ecstasy of love" (2.1.114)—which is quite simply the wrong reason, even if Hamlet is mad.