Because temperature and pressure are directly proportional.
The lower you go in altitude, the less pressure there is in the Earth's atmosphere. As a result, as the gas in the atmosphere rises, it experiences less pressure, causing it to expand. When a gas expands, it produces energy. And if it's working, it's wasting energy; and if it's wasting energy, its temperature must fall, because temperature is defined as the average energy of the particles. As a result, if the particles' energy is lower, the temperature must be lower. That's why the temperature appears to drop with altitude.