Because the earth’s axis is tilted.
It is all about the tilt of the Earth’s axis. Many people believe that the temperature changes because the Earth is closer to the sun in summer and farther from the sun in winter. In fact, the Earth is farthest from the sun in July and is closest to the sun in January!
During the summer, the sun’s rays hit the Earth at a steep angle. The light does not spread out as much, thus increasing the amount of energy hitting any given spot. Also, the long daylight hours allow the Earth plenty of time to reach warm temperatures.
During the winter, the sun’s rays hit the Earth at a shallow angle. These rays are more spread out, which minimizes the amount of energy that hits any given spot. Also, the long nights and short days prevent the Earth from warming up. Thus, we have winter!