A frequently given explanation for seasons is that Earth is closer to the sun in summer. This is wrong, and the evidence against it is immediate: when it is summer in the northern hemisphere it is winter in the southern one, and both are the same distance from the sun.
The actual cause
Earth’s axis is tilted about 23.5 degrees relative to its orbit. That tilt stays pointed the same direction in space as Earth goes around the sun.
For half the year the northern hemisphere leans towards the sun; for the other half it leans away.
Why the tilt produces heat differences
Two effects, both from the same cause.
Angle. When your hemisphere leans towards the sun, sunlight arrives closer to vertical, concentrating energy over a smaller area. Leaning away, the same light spreads over more ground and delivers less energy per square metre.
Day length. Leaning towards the sun puts you in daylight for more of each rotation. More hours of heating and fewer of cooling.
About that distance
Earth’s orbit is slightly elliptical, and it is actually closest to the sun in early January – during northern winter. The effect exists and is small compared with the tilt.
Why the hottest month is not the longest day
Because land and ocean take time to warm. The longest day is around late June in the north, and the warmest weeks come several weeks later, as accumulated heat builds. The same lag makes late afternoon warmer than noon.