How do gaseous planets form?
Identically to the way the rocky planets formed, gravity.
The reason you have four rocky planets near the sun followed by the gas giants is gravity. Gravity's effect upon the particles which went to make the first four planets was greater in two ways. The mass of the particles which went to make up the rocky planets was greater than that of gas. As the hot particles pooled they formed the first four planets. As their individual gravity grew they in turn drew in more particles making them larger and larger.
The gases which make up the gas giants were drawn into quickly cooling solid gas balls. Jupiter, for example, is 90% hydrogen and the rest helium, much like a star. While Jupiter is 318 times larger than the earth its total mass is only 2.5 times larger.
And even though Jupiter is 318 time larger its gravity is only 2.4 times that of earth.