It isn't really quite like that.
First there was a disk of gas and dust around the sun. Gradually, the disk developed little clumps of higher concentrations of gas and dust, and thanks to the force of gravity, these attracted more and more nearby material into themselves until they formed planets and moons. That's the collapsing bit - the collapse of a dust and gas cloud into concentrations, in the form of planets and moons.
The question of the roughly spherical shape is slightly separate. The collapse of the dust and gas produced far more non-rounded bodies (asteroids, for example, and the smaller moons) than quasi-spherical ones.
In each of these bodies, round or otherwise, two forces were fighting it out for supremacy. One was self-gravity, the force exerted by every grain of dust in the object on every other one. Since gravity depends on mass and the distance between the attracting bodies, more massive bodies had greater self-gravity. This self-gravity tended to make them spherical (in the absence of rotation). The reason for that in turn you can think of as being potential energy. For something to be a long way from the centre of the body, it must have a lot of potential energy. You know that from picking things up here on earth. You have to exert a force on the object to be able to pick it up against the force of gravity. By doing work on the object in picking it up, you give it potential energy. If you let go, it gives back that potential energy, by falling. The potential energy of the whole thing is at a minimum (which is the stable situation) when every art is as close to the centre of gravity as it can get. That turns out to be a sphere.
The force working the other way is the rigidity of the material of which the planets are made. If you squeeze rocks just a little, as you know, nothing happens. But if you squeeze them a great deal, as it might be under hundreds of miles of other rocks, they will behave more like putty than the rocks we know. So, if there is only a little gravity, the rigidiy of the rocks wins. If there is lots (i.e. of the moon or planet is large enough) then gravity wins, and the object becomes fairly spherical.