You might have noticed that when you climb mountain, as you go higher and higher, it gets cooler and cooler.
This is because the Earth's atmosphere is like a blanket covering the planet. Heat from the sun enters the atmosphere, and remains below it. Without an atmosphere, the Earth would be a frozen wasteland because heat would not remain on the planet. The higher you go in the atmosphere, the thinner it gets, the less heat it is capable of holding it.
When you climb on the top of a mountain, or fly in an airplane, the atmosphere is so thin that there is a drastic difference in temperature. To put it in a nutshell, it gets colder the higher you go, because the thinner atmosphere allows more heat to escape back into space.