How does gas become a solid without going through the liquid phase?

The process is called "sublimation". When a solid melts to a liquid, it is because there is enough gas pressure to ensure that the molecules will remain grouped together, milling around each other. But if there is not enough gas pressure, the molecules will simply fly away. Any molecular solid can sublime. But ordinary pressures are enough to make sure that for most gases there will be an intermediate liquid phase. A few, though, are like carbon dioxide, and will sublime unless the molecules are forced to stay together by increasing the pressure. Others, like water, will only sublime if the pressure is reduced. Any molecular solid will sublime if the pressure is low enough.