This is a schematic showing how atmospheres form.
Image from: After Moons and Planets