I just re-watched Harry Potter and The Deathly Hallows: Part 2 and was wondering why Snape kept his relationship with Lily a secret from Harry Potter.
Why didn't he let him know that he was on the side of good?
He didn't want Harry to know for 2 main reasons.
He couldn't bear Harry knowing he had feelings for his mother because Harry still reminded him of James, whom he despised. This is explained in the book.
Snape: "But never - never tell, Dumbledore! This must be between us! Swear it! I cannot bear... especially Potter's son... I want your word!"
Harry had a connection to Voldemort's mind. So neither Dumbledore nor Snape could risk Harry knowing that Snape actually is on their side, because Voldemort could've entered Harry's mind and see it too, and their whole plan would've been destroyed. This is still important in Hallows, where Snape is still Voldemort's right hand man and is entrusted with the Headmaster position and thus able to secretly protect the kids at the school. He did help Harry, but having him know the truth would've been too much of a risk.
Reason 2 stems from Dumbledore's strategy "not to put all of my secrets in one basket". In order to keep both Harry's and Snape's missions clandestine, he entrusted only Harry, Ron and Hermione with the secret of Voldemort's Horcruxes (when Dumbledore realized that he was dying and couldn't find the rest himself) and told no one of Snape's true allegiance, thus weakening Voldemort on two fronts without him actually knowing about it.
In addition to Walt's excellent logical analysis, it has to be mentioned that Snape has also spent a great deal of time building an emotional wall and shared little with anyone in order to protect himself.
He only felt truly free to share with Lilly, and to a lesser degree Dumbledore, but with everyone else he was on his guard and worried that anything he said could be used to hurt him. You can see, for instance, his reaction to Harry getting into his mind - even though it was important to the order that Harry learn occlumancy, he dropped teaching him at the first instance that Harry saw, and pitied, Snape.
Harry never learnt occlumency properly and Voldemort is both connected to his mind as well as a practised legimens and has already used this for influencing Harry. That's good enough a reason for Dumbledore.
But with regard to Snape, there is another more dominant reason: he hated Harry's guts. Snape's allegiance is to Lily and he is making her sacrifice count the way she intended it. But his bond to Lily is his own and Harry is the least person he'd want to share it with. He disapproves of her choice for a husband, and he disapproves of the offspring resulting from it.
His self-chosen task is to save Harry, not to like him or associate with him.
It would be about the same if Lily died in order to save a ridiculous annoying yapping puppy.