The temperature of the troposphere decreases with altitude whereas it is opposite in the stratosphere and again fluctuates. Why is this so?
The strong heat flux through the Earth's atmosphere, the presence of greenhouse gases, convection, and mixing conspire to push the troposphere away from thermodynamic equilibrium (isothermal atmosphere) and toward an adiabatic atmosphere. The natural drop in density with altitude means an adiabatic atmosphere is subject to a lapse rate, a nearly linear drop in temperature with increasing altitude.
Temperature rises with altitude in the stratosphere because this is where the ozone layer exists. The troposphere is primarily heated from below. In contrast, the stratosphere is primarily heated from within via absorption of ultraviolet sunlight by oxygen and ozone. A similar situation exists in the thermosphere, which is where the extreme ultraviolet and higher frequencies of sunlight are absorbed.
The thermosphere is where atmospheric temperatures attain their highest values. (BTW, you wouldn't feel those extreme temperatures if you put on a spacesuit and took a spacewalk in the thermosphere. There's hardly anything there that high up.) In between the thermosphere and stratosphere is where atmospheric temperatures attain their lowest values. This is the mesosphere. Most of the extreme wavelength radiation has already been absorbed in higher layers. The mesosphere is too thin to support an oxygen-ozone cycle. All that's left is radiational cooling supported by a strong greenhouse effect, making the top of the mesosphere (the mesopause) extremely cold.