In home canning, food is packed into the jar, leaving some empty "head space" between the level of food and the top of the jar.
The cooling of the contents creates a vacuum in the head space, pulling the lid into tight contact with the jar rim to create a hermetic seal.