why does the temperature decrease as the altitude increases
You must be knowing that air is heated by convection and not conduction. Because of this air is heated by the convection from surface of Earth and not directly from sun-rays. Moreover, density of air is also much higher near surface than that at a higher altitude (It can be explained by effect of gravity).
Hence convection-current is stronger near Earth-surface as compared to that at higher altitudes. Because of this temperature is lower at higher altitude.