All squash is botanically-speaking a fruit. The fruit started out as the ovary, one of the female parts of the flower. Fruit surrounds and protects the seeds. These seeds start out as ovules inside the ovary. To become seeds, the ovules must be fertilized by pollen from the same or another plant's male reproductive parts. Follow so far?
Each seed is pollinated separately by different pollen granules. If, like in the zucchini above, many of the ovules don't get pollinated and thus develop into a seed, the fruit (ovary) doesn't develop. Instead, it grows a little, turns yellow, then rots.
If you are experiencing this frequently in your garden, you need to consider a few things. Are there pollinators flying about? Do they have access to the flowers? The plant above was in a biologically diverse garden but buried in weeds. Once I uncovered it, I found several fruits undeveloped like this. That is because the abundant bees couldn't get in, and this plant is a bee-pollinated plant.
It is so important to make sure we encourage insects in our gardens so they do the job we need them to. If you have a diverse garden with many types of flowers blooming at different times of the season, and you make sure the insects have access to the flowers, you shouldn't experience this very often.