Vertical equilibrium of molecular gas in galaxies