Also, mountains are terrible at holding heat as they lose it immediately as there is no moisture in the air to hold it down like there is on the ground level. Altitude is what changes when it comes to mountains and being cold, it is still the same sun, the same location, and the same time. To further explain that the closer to the sun doesn't mean more heat, we can look at space. Space is a vacuum with no air, or molecules to trap heat.
If we are to understand warmth, it has to do with what the sunlight shines on and how effectively it can retain the heat. If there is a surface to absorb, an atmosphere to trap the heat, pressure, and moisture, but when one is at high altitude, one loses these things. In a desert with no moisture, dry air, while it can be very hot during the day, it can be cold at night. At high altitude, the greenhouse effect exists but it is weaker so they are not able to re-emit heat efficiently.
So when next you are climbing up a mountain, do not go with the notion that the closer you are to the sun, the warmer it will be. Go prepared that you might be meeting extreme cold or freezing temperatures.
Reference
https://www.sciencefocus.com/planet-earth/why-is-it-colder-at-the-top http://scienceline.ucsb.edu/getkey.php?key=4561 https://www.earthdate.org/episodes/cooler-in-the-mountains https://www.astronomy.com/science/how-cold-is-it-in-outer-space/ https://www.livescience.com/why-do-deserts-get-cold-at-night.html https://earthobservatory.nasa.gov/biome/biodesert.php