Harry was caught snooping around in Snape's memories and that indeed triggered an irrational response from Snape.
Irrational? There was more than one memory in the pensieve - no doubt the memories he shared with Harry in the end where also there. Snape realized that Harry's interminable/insufferable curiosity could blow his cover - I assume Dumbledore encouraged the idea with his surprise to misdirect Harry. If anybody suspected Snape was onside after what he had done, his position would be compromised and Hogwarts would have been in the control of less friendly Death Eaters.
That's how I see it anyway.