Why do planets have moons?

Moons are caught by a planet’s gravity — from leftover rubble or a big collision long ago.