Since sun has large mass so its gravitational force is high.
Whether it's a gas or a liquid or a solid doesn't make any difference. The Sun is a lot more massive than the Earth, and so it has a stronger gravitational field. From our everyday experience, it might not be so obvious that a gas has mass, but it's true. The Sun exerts the same gravitational force on the planets as it would if it had the same mass but was made of rock.
This attract gas molecule and there by gas cant escape from its surface