Some types of glue require a chemical other than those found in air. These types of glue won't stick to the bottle even if you leave the cap off.
In some cases, there is a solvent in the glue that helps keep the molecules in the glue from cross-linking (getting sticky). The glue doesn't solidify in the bottle or stick to it because of the solvent. The solvent evaporates in a half-empty bottle of glue, but this is limited by the space in the bottle.