physicist here. while some of the explanations here aren't fully wrong, they're not that easy to understand either. the simplest way to understand is imagining the solar system with basic gravity, but project it onto the z-axis only, ignoring x- and y-. they still exist and do their own thing, we just don't need to worry about them right now.  if we assign all the mass randomly at first, over time it will oscillate towards the centerline. as any physicist will tell you, this looks like a spring, which is extremely easy to model.  so it's actually quite expected for this to happen. it's 1 am here so i'm not gonna code a quick demonstration with an animation, but i made this 3 minute mspaint version of what it'd show. if you've taken an intro to coding or equivalent you can easily make it yourself.
United States