It’s just kind of a strange coincidence. The diameter of the Sun is about 400 times larger than the Moon's, but it is also roughly 400 times farther away from Earth. These two qualities almost cancel each other out, and the Sun usually winds up looking either the same size or just a wee bit bigger than the moon to us.
How do we know how far away and how big the Sun and Moon are in the first place?
Since we can’t just wrap a giant measuring tape around a celestial body, we have to get a little creative.
Look up at the sky and imagine it as a big dome, which goes all away around the Earth, with the Sun, Moon and stars projected onto its surface. This is a neat little hypothetical that astronomers call the celestial sphere. If we think of the sphere as being 360 degrees, like a circle, we can talk about the things we see on the dome in terms of angular size (that is, the “visual diameter” of the object measured as an angle) and angular distance (the distance separating two objects measured as an angle).
We’ve been able to get a better handle on the actual distance thanks to spaceflight and laser and radar technology. For the Moon, Apollo astronauts left retro-reflectors on its surface, which we bounced lasers off of from 1969 to 2009. By timing how long it took for the laser beam to make the trip there and back, astronomers could work out the Moon’s physical distance.
For the Sun, we tried the same sort of thing and bounced radio waves off it, but the star’s outer atmosphere scattered the waves too much for accurate measurements. Astonomers switched to a more reliable method that uses German astronomer Johannes Kepler’s Third Law of Planetary Motion, observations of the other planets’ movements, and radar measurements of their distances to work out an indirect, but accurate, measurement for the distance of the Sun.
Once we have the angular size of something in the sky and its actual distance, we can use them to calculate the object’s physical diameter.
But don't get used to them looking this way
The Sun and Moon didn’t always look so close in size from Earth, though, and they won’t continue to do so forever. The Moon is moving away from Earth at a rate of about 4 centimeters per year. In a few billion years, our descendants won’t be looking up at the same sky we are, and the size difference between the Sun and Moon will be much more noticeable.