Solid planets (like Earth) are made from gas and dust particles colliding and sticking together as they orbit a star. The more mass that is sticking together the more gravity there is. The gravity originates from the center of a planet, so gravity pulls down from every direction, creating a sphere.
It’s the same for Gas Planets as well, except there’s only gas and relatively no mass sticking together.