Note: In this post, I discuss events that occur in the last three Harry Potter books. I'm going to assume that you've read them, so there are spoilers.
As I argued in Harry Potter and the Book of Double Entendres, Harry Potter is filled with sexual symbolism. What I left out of that discussion was Severus Snape. Since the last three books are so central to understanding his character, I thought it would be more appropriate to consider Snape on his own in the context of those three books.
Like any teenager, Harry must face anxiety about his sexuality and what kind of person he is through his physical and emotional relationships. But who is the focal point of this anxiety? For whom does he have the greatest unfulfilled desire for connection? Not Ginny, certainly; Harry's biggest worry with her is whether or not Ron will punch him in the face for liking his sister. Cho Chang was definitely the early focus of Harry's attraction, but he abruptly lost interest in her in the fifth book--where, I would argue, his anxiety over rejection became embodied by none other than Severus Snape.
Snape is most certainly the sexiest character in Harry Potter, but why? He's repeatedly described as being physically unattractive and unpleasant. And, just as with all the other teachers in Hogwarts, we know nothing of his personal relationships and assume he doesn't have any. However, he is interesting, and we're fascinated by him--because Harry is. This comes to a head in Order of the Phoenix, where they forcibly and repeatedly penetrate one another in an attempt to teach Harry occlumency. The sexual overtones are underlined by small, unconscious actions such as Snape "tracing his mouth with one long, thin finger" whenever he looks at Harry.
It's no wonder Harry hates his occlumency lessons, as Snape recurrently violates Harry's mind, then berates him for being weak. But what frightens and infuriates Snape more than anything is when Harry reciprocates this insertion, catching a glimpse of Snape's own memories, making him vulnerable and inspiring a feeling of sympathy and camaraderie in Harry that Snape summarily rejects. This isn't the first or last time Harry recognizes a connection to Snape, only to have it turn into a feeling of abhorrence when Snape pushes him away.
For example, in The Half-Blood Prince, further parallels are drawn between Harry and Snape. After a lesson in Defense Against the Dark Arts, Harry fumes about Snape's passion for dark magic until Hermione points out that he sounds exactly like Harry. Meanwhile, unknown to either us or the book's characters, Harry is developing a man-crush on Snape's young alter ego, the Half-Blood Prince. The Prince is helpful, absolutely brilliant, funny, and the best teacher Harry's ever had. The depth of his attachment to the Prince is apparent in his hope that his father is really the Prince, even though logically he knows this can't be the case.
The point in all this is to say that Harry and Snape are not anathema to each other; quite the opposite. They're very similar and instinctively attracted to one another. In The Sorcerer's Stone, Harry is excited about potions until Snape makes it clear the first day of class that Harry's on his shit list. This pattern of constant attraction and rejection is what fosters in Harry his loathing of Snape--other teachers are hard on him and he dislikes many classes, but it is failure in Snape's class and his criticisms that really sting, because Snape is who he intuitively connects to.
But why does Snape repeatedly reject Harry? By the time we get to The Deathly Hallows, Harry burns with hatred for Snape, and with good reason: as far as he knows, Snape has betrayed the trust of Dumbledore and murdered him in cold blood. But like all passionate emotions, Harry's feelings for Snape aren't that far away from their opposite, in this case love. What Harry sees in Snape's dying memories appeases the negativity of the characters' interactions by once again reaffirming their connection and giving Harry the reason behind Snape's rejections.
Snape's objection to Harry is always that he's exactly like his father, James, a man Snape hated. But as Dumbledore points out, Harry is also very similar to Lily, the woman Snape loved. Therefor, to Snape, Harry is the embodiment of the pain and attraction he experienced as a youth, especially as he's the child Lily had with another man, and a living witness to her murder that Snape was indirectly responsible for. Snape is, perhaps, as attracted to Harry as Harry is to him; but he's also repulsed--by himself, his past, and his actions, all of which Harry is a breathing reminder. One might ask why Snape didn't simply choose to ignore this and instead focus on the positives and the connection he might have built with Harry, but his final memories show why he did not. Snape is completely unfamiliar with how to connect with people; not only that, but how to forgive others and himself. So he fell back on something he was more than practiced in, pushing the person he was most attracted to away.
Nevertheless, Snape recognizes that Harry is the only person at Hogwarts who can truly see him. That's why he demands Harry look at him as he takes his final breath. And would Harry take time out from defeating Voldemort to go wandering around the memories of a man he truly hated, or cared nothing for? Would he name his own child after someone he could never understand, call him the bravest man he ever knew (and that's saying something)? No. Harry never hated Snape, even at his angriest moments. Snape's rejection hurt him, and thus Snape became a symbol of Harry's sublimated desire for a connection with an older male figure. The sexual connotations that occasionally appeared with Snape in the context of that desire are, I think, not a sign that their attraction was sexual in nature, but merely one of the many reasons why it was destined not to go anywhere.