Ophelia is quite distraught when she comes to see her father after Hamlet has visited her (after Polonius asked her to make herself scarce to Hamlet). She recounts this story:
Ophelia was in her room, sewing, when Hamlet walked up to her--looking a mess. His clothes were disheveled, his knees were knocking, and he had a look on his face
"As if he had been loosed out of hell to speak of horrors."
He didn't speak to her, though. He simply took her wrist, walked away from her, and dramatically placed his arm upon his brow. Then,
"He falls to such perusal of [her] face as he would draw it."
He stayed that way for a long time; then he shook her arm a bit, nodded his head three times, then
"raised a sigh so piteous and profound
As it did seem to shatter all his bulk
And end his being."
Finally, he walks out the door backward, maintaining his gaze with her until he left.
That's enough evidence for Polonius--obviously Hamlet is mad for her love. Ophelia is just afraid Hamlet has gone mad, though she does not necessarily attribute that to lovesickness, as Polonius does. We, as audience, find this rather out of character and melodramatic, making it one of the rare comic moments in the play.
Ophelia has been instructed by Polonius to stop communicating with Hamlet -- to "repel his letters" and deny him access to her. So when Ophelia comes to report Hamlet's behavior to Polonius, she is motivated by more than fear. She is being the dutiful daughter. The incident she relates suggests that something is terribly wrong with Hamlet. At this point in the play, the audience may doubt whether it's genuine madness or merely a clever attempt to appear mad. Ophelia fears it's the former.
Ophelia begins by describing the extreme nature of Hamlet's appearance. He isn't merely disheveled or failing to live up to the formal dress code; he's downright dirty ("stockings fouled") and rather shockingly undressed. His doublet (jacket) is "unbraced" (or completely open), and his dirty stockings are pooled around his ankles. Gentlemen in Shakespeare's day wore thigh-high stockings. This was a world without elastics, so the stockings were held up with garters. Hamlet (Ophelia tells us) is "ungart'red." Additionally, he looks pale and his knees are knocking together.
It presents us with a clownish, weird picture, and that's important. This isn't the image of someone being a bit rumpled. This is someone making himself ridiculous. We might imagine the scene is purely comical, except that Ophelia notes the look on Hamlet's face ("as if he had been loosed out of hell"), and she is clearly very upset ("I have been so affrighted!").
Ophelia goes on to describe Hamlet's movements. They sound like something we'd expect from bad melodrama:
- Hamlet's hand over his brow while he stares at her
- his odd head movements ("Thrice his head waving up and down")
- a sigh "so piteous and profound / as it did seem to shatter all his bulk / and end his being"
Even Hamlet's exit is over-the-top. As he walks away from Ophelia, he never stops staring back at her. She seems to wonder how he managed to find his way outside without looking where he was going.
The scene might be dismissed as an attempt at comic relief (despite Ophelia's obvious distress), but we're being given an important piece of information: Either Polonius is correct, or Hamlet has engaged in a ruse. If it is the latter, Hamlet has gone to great lengths to look foolish and out-of-control -- and to make people think his madness concerns his relationship with Ophelia. This will help keep his uncle from guessing why Hamlet is really upset.