When the mercury warms to the same temperature of the glass, it is then forced up the glass tube because of its greater expansion rate. It is not an exception. The air, when heated, does expand. Although the house may expand a little, it doesn't expand enough to make room for the larger volume of air. Some of the air leaks to the outside.
Thin glass is used because of the sudden temperature changes.
If the glass were thicker, unequal expansions and contractions would break the glass with sudden temperature changes. In the construction of a light bulb, it is important that the metal leads and the glass have the same rate of heat expansion. If the metal leads expand more than glass, the glass may crack. If the metal expands less than glass upon being heated, air will leak in through the resulting gaps. On a hot day a steel tape will expand more than the ground.