>>11204706gas has mass and responds to a gravitational pull, or exerts it's own gravitational pull
so if you have a rocky planet with enough gravity and maybe a magnetic field, gas will collect on the surface, or gas can clump together to make stars and large gas giant planets