Pilot lights are often designed so that the heat from the flame holds a bimetallic switch in the open position. Should the light go out, the bimetallic switch will shut as it cools.
Natural gas is mostly methane, which is lighter than air and easily escapes most structures.