The question of how a mountain so close to the sun can be cooler than the valley below has been asked and wondered here in the Appalachian Mountains for some time now but there is an answer to this!

The air atmosphere is warmed by the radiation from below Earth, and this makes the valley much warmer than that of the mountains. As the air rises in elevation, the air encounters lower pressures and is a much thinner air.
The further away you get from the Earth’s surface, the thinner the atmosphere gets therefore causing higher elevation to have cooler temperatures versus lower elevation having warmer temperatures.
If a person stands at the foot of the mountains, you might not realize since the air mass is lighter than compared to other masses for instance if the air was water you would notice. As you get closer to the top of the mountain the air gets more space to roam than below sea level causing the air to turn from warmer to colder. Below sea level though the air is sort of trapped and therefore produces warm air with the trapped energy.
Although the Sun does still produce heat it is 93 million miles away from Earth and Space is not warm so the higher in altitude that you climb in the atmosphere the cooler the air gets. However, the sun does heat up the Earth’s ground and in return the air makes contact with the ground and then heats the air up, then expands and then later cools.
Air in our atmosphere is kind of like a basketball, it moves up and down and this creates our weather!
Cooler higher altitude air sinks down and is compressed as it descends further down and is heated as this occurs. The process is called convection.