Explanation:
Dumbledore dies in Harry Potter and the Half-Blood Prince.
This is when Harry finds out that Severus Snape is actually Dumbledore’s man, and that he has been working for him all along.
After Dumbledore dies, Snape takes over as headmaster at Hogwarts.