Planets are formed around compounds of metals and dust. So gravity pulls then to eachother which gets bigger and bigger, agreed? Well this gravity pulls from every single angle which would be a sphere rather than cube
A sphere has the smallest surface area per volume making it the simplest shape to conform too under certain pressures. Gravity which wants to pull everything to a central location if strong enough will then cause a large enough mass to take this shape.