When the planets were forming, they were in a molten state. In any object, gravity pulls from the centre, and parts of the object at the same distance from the centre are pulled inward with equal force, creating a sphere. This will only happen to objects with sufficient mass, such as planets and stars. Smaller objects, such as asteroids, have a weaker gravitational force, so they cannot pull themselves into a spherical shape. Gravity is also responsible for denser materials being pulled to the centre of a star or planet.

Planets are round because of its gravitational field. As a planet gets massive enough, internal heating takes over and the planet behaves like a fluid. Gravity then pulls all of the material towards the center of mass (or core). Because all points on the surface of a sphere are an equal distance from the center of mass, planets eventually settle on a spherical shape. For major planets, one of the requirements is that it’s large enough for its gravity to pull it into a sphere. Though, even for small asteroids and such, it’s not uncommon for these bodies to be “roundish” (though, they are often oval shaped).

It is interesting to note though that, because planets rotate, they aren’t perfect spheres and actually bulge out at the equator.

In the case of a cube, the corners are further away from the center of mass than the rest of the cube. Especially for objects as massive as a planet or a star, the corners would collapse under their own weight and the object would take on a spherical shape. As cool as a cubical planet would be, they simply can’t exist. Well, correction, a cubic planet could probably be engineered by a civilization bent on assimilating all life in the galaxy, but the point is a square planet won’t form without outside help.