Hamlet's feigned madness is an act to confuse whom he believes are his enemies, specifically King Claudius, Ophelia's father, Polonius, and others (including his mother) for he believes that they had plotted the murder of his father, King Hamlet, and denied him rightful succession to the crown. Hamlet believes that his seemingly mad behaviour will hide his true intentions, which are to implicate the perpetrators and then exact his revenge.
Unfortunately, Ophelia also becomes a victim of Hamlet's deception. She is deeply in love with him, and his behaviour confuses her. He, at times, expresses his love for her and then, at others, rejects, mocks, and insults her. This obviously has a profoundly emotional impact on her and makes her uncertain. Added to this are also her father's continuous meddling and her brother Laertes' admonitions. Both warn her of getting involved with Hamlet. Adding fuel to her already smouldering emotional coals, is the fact that her father uses her to get more information about Hamlet's mood and mental condition.
Ophelia is truly at sixes and sevens. When Hamlet kills her father when he mistakenly believes that it is Claudius hiding behind the curtain in his mother's chamber, she completely loses it. She is so traumatised by this event that she suffers a nervous breakdown. She goes around singing meaningless ditties and uttering nonsensical statements. This tragically culminates in her suicide - she makes no effort to save herself when she falls into a river, and drowns.