God did not tell us why he created planets. Planets are the natural result of gravity acting on the matter in the universe which God created. If we assume that God had a "purpose" in creating a universe with planets, then the most obvious purpose is to provide a place where life can exist. Most likely planets are the only place in the universe on which life can exist. A planet has sufficient gravity to accumulate an atmosphere. Some (but not all) planets have the appropriate ambient temperature to allow for life, as carbon-based life can only exist between about -20 and 80 degrees centigrade.
Another "purpose" of planets is worth mentioning. When a solar system forms due to gravitational attraction of interstellar material, smaller hotter rocky planets form. These are the ones on which life can exist. In addition, much larger, gaseous planets, composed mostly of hydrogen, methane, ammonia and water, also form. In our solar system Jupiter, Saturn, Uranus and Neptune are gas giants. These planets have the property of sweeping up the vast majority of large objects in the solar sustem. If the earth were struck by very large objects such as asteroids or comets, it could destroy all life, or at the very least cause huge extinction events. In fact, there is evidence one of these extinction events occurred 65 million years ago, resulting in the elimination of dinosaurs, causing mammals to become dominant. If it were not for the gravitational field produced by the gas giants, physicists predict that such collisions with the earth would be much more common, and most likely sufficiently advanced life forms would not have evolved and presumably we would not exist.
Probably there are other "purposes" of planets, but being a place for life to exist and protecting rocky planets with life from destruction by space debris are two good examples.