In Deathly Hallows we learn Snape was in love with Lily, so he risked his life becoming a double agent in order to protect Harry.
But in Order of the Phoenix, instead of strengthening Harry's protection against legilimency, he weakens it, granting Voldemort access to Harry's mind.
Then, why did he risk Harry's life, if he was risking his own life to protect him?