I don’t claim to know how planets and stars are made, I haven’t particularly studied the physics of the matter.
From just my college lectures, I recall planets being made from asteroids which collide with one another and attaching to one another due to their mass and gravity.
But the answer you want to ask me is why they exist. I personally believe in an ever existing universe with specific laws of physics and all matter is moving based on those laws.
A follow up remark one would make is: who made this ever existing universe? Their answer would be God and they would say that God somehow was always existing. But the difference is that I know I exist and that I exist in some entity known as the universe; whereas God I have no knowledge of.