This is a really great question and not my speciality (ask Phil I think), but my understanding is that rings can form in a lot of different ways. Saturn, Uranus, and Neptune’s rings might have formed by a moon that got too close to the planet and was ripped apart by its gravity (Mars’s moon Phobos will do this one day, and Mars will get a ring!). Jupiter’s rings form from dust coming off two of its moons as they zoom around.
Moons and asteroids can also have rings though! Saturn’s moon Rhea and the asteroid Chariklo are two other confirmed ringed objects in our solar system.