To explain the nearly spherical shapes of celestial objects, we need a little bit of basic physics. Here it is: there is a general law of motion that says that an object always accelerates in the direction that reduces its total potential energy as quickly as possible. In other words, if an object can decrease its potential energy by heading in a particular direction, it will tend to pick up speed in that direction.
This law arises because the forces that cause accelerations are intimately related to the potential energies that are stored in those forces. Thus a ball rolls downhill to reduce its gravitational potential energy, a spring snaps open to reduce its elastic potential energy, and a magnet jumps toward your refrigerator to reduce its magnetic potential energy.
This law of motion has a dramatic effect on celestial objects. Whenever a part of such an object can reduce its gravitational potential energy, it will accelerate in the direction that makes that happen. Thus all the pieces of the celestial object tend to keeps sliding, rolling, bending, or twisting in directions that take them further and further downhill. Eventually, the entire object reaches the compact shape that minimizes its total gravitational potential and that shape is a sphere.
In planets like the earth this approach to spherical isn't quite complete. As the object gets rounder and rounder, it has fewer ways to decrease its gravitational potential energy and other potential energies become more and more important in determining accelerations and shape. For example, elastic potential energies in the earth's crust oppose gravitational potential energy and keep the earth from smoothing out into a perfect ball. That's why we still have mountains and valleys.
But fluid objects such as stars could flow into perfect spheres if it weren't for more subtle issues like thermal energy flow and rotation. Temperature differences keep the parts of any star from sitting still and rotation introduces accelerations that widen a star at its equator. So while a sphere is the ideal goal for any celestial object, there is always something that keeps that goal just out of reach.
Answered by Louis A. Bloomfield of the University of Virginia