As far as I know (the big) planets carve out their path in their orbit around the Sun.
Clearing out all the space rubble, dust and rocks which may start colliding with each other, slowly forming moons that are pulled along by the gravity of Jupiter/the planet.
Jupiter, with its large gravities, cleared out massive areas from the disc of dust and such. Many moons.
Hello u/Burning_Toast998, your submission "How can moons be formed around planets like Jupiter or Uranus?" has been removed from r/space because:
Such questions should be asked in the "All space questions" thread stickied at the top of the sub.
Please read the rules in the sidebar and check r/space for duplicate submissions before posting. If you have any questions about this removal please message the r/space moderators. Thank you.
Zenbast t1_is4vosr wrote
Here is an article that may interrest you.