The Whomping Willow is planted at Hogwarts

"They planted the Whomping Willow the same year that I arrived at Hogwarts. People used to play a game, trying to get near enough to touch the trunk. In the end, a boy called Davey Gudgeon nearly lost an eye, and we were forbidden to go near it."
-- Remus Lupin (PA10)

The tree is magically enchanted to protect what is concealed in its roots: the entrance to a secret passage to the Shrieking Shack. It is planted so that when Lupin arrives as a student, he can be taken by Madam Pomfey to the Shrieking Shack once a month when he transforms into a werewolf:

“I told you, months ago, that the Whomping Willow was planted the year I came to Hogwarts. The truth is that it was planted because I came to Hogwarts. This house” — Lupin looked miserably around the room, — “the tunnel that leads to it — they were built for my use. Once a month, I was smuggled out of the castle, into this place, to transform. The tree was placed at the tunnel mouth to stop anyone coming across me while I was dangerous” (PA18).

The connection between the Whomping Willow and the Shrieking Shack is kept secret for the next two decades — even Fred and George, who could see the secret passage on the Marauder’s Map, assumed that no one had used the passage because the Whomping Willow was planted right on top of it (PA10).