Right after Hamlet's famous "To be or not to be" soliloquy, he confronts Ophelia with his "Get thee to a nunnery" monologue. During the play-within-the-play scene (in Act III, I think), he and Ophelia have another exchange in which he accuses her of wantonness.
In both scenes we are led to believe that Hamlet's treatment of Ophelia is part of his feigned madness. In both scenes, however, Hamlet's feigned bitterness towards Ophelia seems like more than acting. His true feelings seem to be breaking through his mask of madness.
Do you think Hamlet's nastiness towards Ophelia is deflected resentment towards his mother and her incestuous relationship with Claudius, his uncle? Do you think Hamlet might be trying to protect Ophelia? That is, do you think his nastiness is an attempt to keep her as far away as possible from his plot to kill Claudius and protect her from harm and suspicion? Or. at times, do you think Hamlet may have genuinely lost his mind, if only temporarily?
It seems to me that there is a bit of a back story that we are not fully apprised of that would tend to support the idea that Hamlet is truly, deeply, hurt by Ophelia, and vice versa. For instance, Ophelia refers to "remembrances" that Hamlet gave her, which she returns because Hamlet no longer seems to feel the same way about her. In many ways, their relationship represents one of the most tragic aspects of the play. Hamlet must focus on revenge, and feels he has to feign madness, and alienate Ophelia, to achieve it; and Ophelia has been specifically instructed by Polonius not to respond to Hamlet's attempts at wooing her. His "get thee to a nunnery" speech to Ophelia is cruel, withering, and seemingly in earnest.
I like to think of Hamlet as a young man thrown suddenly into an untenable situation. I do not think he was mad, exactly, but I do think he was battling with a lot of emotions during that time. He faced insecurity, grief, guilt, frustration, and anger. It's no wonder he acted strange!