After Hamlet meets with the ghost of his father in act 1, scene 5 of Shakespeare's Hamlet, Hamlet confides to Horatio and Marcellus, "I perchance hereafter shall think meet / To put an antic disposition on" (1.5.191-192). In other words, Hamlet thinks that based on what the ghost told him, it might be a good idea to act as if he's mad.
Hamlet doesn't explain to Horatio and Marcellus why he thinks it might be a good idea to feign madness. However, Hamlet tells his mother in act 3, scene 4 that he's acting "not in madness,/ But mad in craft" (3.4.203-204), in order to protect himself from Claudius, who Hamlet believes killed his father.
To Shakespeare's Elizabethan audience, an "antic disposition" didn't mean that the person only performs crazy antics, as is commonly believed today, but that the person exhibits symptoms of "melancholia," such as deep sadness, depression, dejection, and hopelessness.
Interestingly, in act 1, scene 2, Claudius and Gertrude complain about Hamlet exhibiting this very kind of behavior, even before the ghost of Hamlet's father appears to him. This leads to the question of whether Hamlet was simply acting mad, or if he really was mad—a question which has been discussed probably from the time Hamlet was first performed in 1600 or 1601.
Nevertheless, after Hamlet decides in act 1, scene 5 to put on an "antic disposition," it appears that the first person on whom he practices his new "mad act" is Ophelia, and she immediately runs to her father, Polonius, to tell him about it.
Hamlet's performance for Ophelia contains elements of crazy, disturbing behavior, as well as what the Elizabethans considered "antic," melancholic behavior.
OPHELIA. [to Polonius] 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
To speak of horrors, he comes before me.. ...
And thrice his head thus waving up and down,
He raised a sigh so piteous and profound
As it did seem to shatter all his bulk
And end his being. (2.1.87-94, 105-108)
Polonius immediately jumps to the wrong conclusion, which is exactly what Hamlet hoped would happen.
POLONIUS. Mad for thy love? (2.1.95)
Ophelia is confused by Hamlet's behavior, and she doesn't really know what to think about it, so she simply agrees with Polonius.
OPHELIA. My lord, I do not know,
But truly I do fear it. (2.1.95-97)
In time, Claudius and even Polonius start to wonder if Hamlet's madness is just an act, but Hamlet's "antic disposition" serves its purpose to keep Claudius guessing about what Hamlet actually knows about his father's murder.