To illustrate @johnforkosh's point, here is a brief example. In the absence of convection, let's first imagine a vertical tube filled with air, extending from the surface of the earth up to, say, 100 miles. At every height increment going upward from zero to 100 miles, the equation of state of the air (approximated by something called the ideal gas law) relates the pressure, temperature and density of the air in such a manner that when the pressure decreases, so does the temperature. Since the pressure in the atmosphere decreases exponentially with increasing altitude, so will the temperature. Near the earth's surface, this is fairly well-approximated by subtracting five degrees F per 1000 feet of altitude gain, which is why mountain peaks are colder than the valleys between them.
In the presence of convection, the atmosphere gets stirred up vertically which moves hot, low-density air away from the surface of the earth and up into higher altitudes. As it rises, the warm air encounters progressively lower pressure which causes it to expand and as it expands, it cools.
This simplified view ignores the effects of heat exchange between different bodies of air and between air and the ground (a condition called "adiabaticity"). When heat exchange is allowed, the situation becomes far more complicated, and entire chapters of books about atmospheric dynamics are devoted to it.