Are molecular optimizations in quantum chemistry really in vacuum?
You raise an excellent question and the short answer is "yes, quantum chemistry calculations are intrinsically in vacuum".

Approximate methods like semiempirical (AM1, PM6, PM7) and hybrid DFT methods (e.g., B3LYP) use experimental data, which often comes from crystal structures.

For many years, single-crystal x-ray diffraction studies were the gold standard of "what is the geometry of a molecule." Performing gas-phase measurements of bond angles and bond lengths are extremely difficult, since they typically require a molecular beam of the intended target and then very high resolution IR,  rotational spectroscopy, or gas electron diffraction.

I once heard a talk by an extremely talented theorist, who asked the question "is an experimental crystal structure accurate enough?" He showed that in many cases, the answer is "no." (Consider that establishing the position of hydrogen atoms is difficult if not impossible with many single crystals.) The method he was proposing (geometry optimization with CCSD(T) and a basis set limit) isn't really appropriate for large molecules.

Until there's some huge database of gas-phase molecular geometry measurements and CCSD(T) calculations, most methods are compared with crystal structures.