As air rises farther from the earth's surface, it comes under less and less pressure. If you think about it, this makes perfect sense. At ground level, there's a great volume of air stacked-up for miles above the surface, all of it being pulled toward to the ground by gravity. Meanwhile, air at the surface is being squashed beneath the weight of all that air above and therefore is under a much greater pressure. But air that has managed to rise, say, halfway through the atmosphere no longer has all that mass weighing down on top of it. Instead, it's only got half of the weight above it. As a result, it's under a lot less pressure.
Continuing now, doesn't it make sense that the higher altitude air can more easily expand, without all that extra weight pushing down on it? That's exactly what happens. The air aloft expands and has less pressure pressing against each of its molecules.
Why does pressure affect temperature?
Higher temperatures are generated by molecules in motion, banging into each other and causing friction. But once those molecules are not as tightly packed, they bump into each other less and less and the air in which they exist begins to cool. By the way, this process is called adiabatic temperature change, which basically describes a change in the temperature of a gas due to a change in its pressure.
Pssst. Still reading this? Great. This next part is only for us science types...
Here's a little experiment you might want to try with a bicycle pump to help understand this process of adiabatic heating/cooling a bit better. Plug the pump into a partially flat bike tire and start pumping. As the tire becomes more filled, you may be able to detect the pump or pump handle becoming warmer. This is because the air inside the pump is becoming more and more pressurized as the tire fills-up and the air inside it pushes back into the pump's chamber. The pump's air is now warming under that increased pressure. Next, unplug the pump. Hear all the air seeping out? Give it a couple of minutes. Now, feel the pump again. It should be cooler, because its interior air is no longer under as high a pressure. The air in your bike pump has just experienced adiabatic warming and cooling---and so have you, in a way!