Why it is colder in mountains, at high altitudes?
One answer is that mountains on Earth aren't all that tall. An impossibly tall mountain would see temperatures vary with altitude as depicted below.
Tall as it is, even Mount Everest doesn't extend into the stratosphere. This is a question about the lowest layer of the atmosphere, the troposphere. Temperature in the troposphere generally (but not always) decreases with altitude because of four key factors:
- The incoming energy from the Sun is predominantly in the visible and near infrared, which represents one of the few windows in which the atmosphere is fairly transparent.
- The outgoing energy that balances the incoming energy is in the form of thermal infrared radiation. The atmosphere is quite opaque in this frequency region thanks to the trace greenhouse gases in the atmosphere.
- The air in the troposphere is always in motion. The name "troposphere" means just that, the constantly turning part of the atmosphere.
- Air is a very poor conductor of heat.
All four are important. Temperatures rise with increasing altitude in the stratosphere and thermosphere because those portions of the atmosphere absorb the high frequency components of the Sun's output. The greenhouse effect is also very important. A dwarf planet in the outer reaches of the solar system with a pure helium atmosphere would have a nearly isothermal atmosphere because helium is not a greenhouse gas. Finally, mixing is important. For example, Los Angeles has serious problems with smog because temperature inversions often set up that keep the air around LA stagnant. The short mountains around Los Angeles are often warmer than is Los Angeles itself.
The latter two reasons mean that the troposphere is approximately adiabatic. Parcels of air expand and cool adiabatically as they rise, contract and warm adiabatically as the fall. An adiabatic atmosphere is the steady-state condition for an atmosphere that is warmed from below and cooled from above. It is also a local maximum with regard to entropy.
The global maximum with regard to entropy would of course be an isothermal atmosphere. A ten kilometer tall thermally insulated cylinder of gas would evolve toward an isothermal temperature rather than the (roughly) linear lapse rate we see in the Earth's troposphere. So why don't we see that in the Earth's atmosphere? The answer is that the four factors listed above keep the Earth's atmosphere very far from thermodynamic equilibrium. The Earth's atmosphere is the canonical example of non-equilibrium thermodynamics.
As an extreme example, consider Venus. Venus's atmosphere isn't in constant flux the way our troposphere is, and very little sunlight reaches the surface of Venus. However, almost all of Venus' atmosphere is in the form of greenhouse gases. The extreme greenhouse effect on Venus creates the conditions that enable an adiabatic temperature profile, which is why Venus' surface is so very, very hot.