The thermal profile of planetary atmospheres is well understood and can be completely explained. The temperature as a function of height above the surface of a planet depends on the atmospheric:
chemistry
structure
fluid dynamics
surface pressure
The surface pressure depends generally on the gravity and size of the host planet and total mass of atmosphere. Pressure always decreases exponentially with height:
P = P0 exp(–z/z*) where z* = kT/mg
The strongest factor that changes the thermal profile of an atmosphere is the m in the equation, which is the average molecular mass. Depending on the chemistry, this can absorb or emit in the IR. For example, Earth's stratosphere gets warmer with height above the surface because of the presence of O3. There is much more to be said of this, but that is a general overview of thermal gradients in planetary atmospheres.
The lower temperature of Earth's atmosphere around 20 km is also called a 'cold trap' and is caused by molecular nitrogen.
See Wikipedia article here: https://en.wikipedia.org/wiki/Cold_trap_(astronomy), and more on the role of nitrogen here: http://adsabs.harvard.edu/abs/2016AGUFM.P52A..02W
The fall of temperature with increasing altitude (a negative temperature gradient) is found in the lower atmospheres of all planets, and is due to the tendency of the lower atmosphere to be in adiabatic equilibrium. That is, the temperature gradient is nearly the same as the gradient required to maintain a more-or-less stable atmosphere. If the temperature does not fall fast enough with altitude, heat builds up at lower altitudes, increasing the temperature gradient until vertical convective motion occurs, which carries heat upwards, tending to stabilize the temperature gradient at near adiabatic equilibrium. If the temperature gradient is too large, the vertical convection carries heat upwards too fast, reducing the temperature gradient until it is once again near adiabatic equilibrium, cutting off the vertical motions.
The rate at which this occurs depends on the composition of the atmosphere and the surface gravity of the planet. As it happens, this causes the Earth to have the fastest decline in temperature per vertical mile, while the Jovian planets have the slowest change; but for every planet, the lower atmosphere, on average, has a temperature gradient close to the adiabatic value.
In the upper atmosphere, the temperature always rises to very high values at great height, due to interaction of the solar wind with the upper atmosphere. So the temperatures are higher at the top and bottom of the atmosphere, producing a "cold trap" in the middle atmosphere. For most planets that is very nearly the end of the story, but for the Earth (due to the absorption of UVB and UVC radiation by oxygen and ozone) and for Titan (due to the absorption of the same radiation by methane-related compounds), there is an additional heat source in the lower middle atmosphere. In those cases, the "cold trap" is in the region just above the region heated by the absorption of ultraviolet light.
For a more thorough discussion of this topic, refer to the following pages on my website (intended as a reference for my students when I was teaching, and maintained as a general reference for everyone else now that I have retired from formal teaching):
The Structure of the Earth's Atmosphere at http://cseligman.com/text/planets/atmosstructure.htm (contains definitions of the various terms used to describe the structure)
(the "cold trap" is at the mesopause)
The Structure of Planetary Atmospheres at http://cseligman.com/text/planets/atmospherestructure.htm (includes a detailed discussion of the concepts noted above)
(in the diagram showing the temperature structure of Jupiter's atmosphere the "cold trap" is just above the first recorded measurement by the Galileo probe)