When sunlight hits the ground, it heats up the soil.
When sunlight hits the leaf of a tree, the leaf uses the energy to break CO2 molecules apart, releasing the oxygen and using the carbon to produce wood. The reaction consumes the energy, preventing it from becoming heat.
Trees are nature's air conditioning.