High altitudes are closer to the sun, which means that they should be slightly warmer. Furthermore, the moisture from clouds should keep these altitudes at an even temperature. So why do airplanes need heating systems and mountain climbers get frozen?
Most people will recognize, when reading the above paragraph, that a few thousand feet closer to the sun doesn't make all that much of a difference, considering the 93 million miles that the light from the sun already has to travel to hit earth. At first glance it doesn't make sense that high altitudes, with so little atmosphere to keep the air an even temperature, wouldn't get blisteringly hot, at least during the day.
But it's the lack of atmosphere, or rather, of atmospheric pressure, that sucks the heat out of high places. At sea level, the pressure is around 14.7 pounds per square inch. At five thousand feet it's around 12.2 pounds per square inch. While humans are comfortable at either level, that's quite a change in pressure.
For gases, a change in pressure means a change in temperature. Depending on the conditions, there can be a lot of ways to look at this. One is that pressure is an outside force, and pumps energy into the thing it is pressurizing. Looked at that way, it's natural that gas molecules under high pressure would be at a higher energy level than gas molecules under less pressure. Another is that with a decrease in pressure gas often increases in volume. If the same number of gas molecules are in a bigger space, they don't jostle into each other as much, and their total kinetic energy is spread out over a larger area, lowering the average temperature.
Air molecules at low altitudes are crowded together in cities. Rough, unpredictable, they're likely to bounce off each other, and run riot through the streets, and go to nightclubs with guns stuck in the waistbands of their jean shorts. They're at a high energy and that makes for a high temperature.
Meanwhile, high altitude air molecules wander in solitude, a pack on their back and a cranky yak carrying their tent behind them. They have more space to wander around in, and because they don't bounce off each other as much, because they're not crammed into a small space by the pressure of the air above them, each square inch has a much lower temperature than sea level air.
Which is why, if you're climbing Mount Everest, you should bring a sweater.