The hinge sits across the plastron, the lower shell, in a line of flexible connective tissue between the pectoral and abdominal scutes. Muscles pull the two lobes upward until their edges meet the carapace. The seal is tight enough that a determined predator generally gives up.
The ability develops with age. Hatchlings have a plastron that does not yet close, and the hinge becomes functional over the first several years, which is one reason young box turtles suffer far higher mortality than adults.
The strategy works against predators and fails against roads and collectors. Box turtles are long-lived, slow to mature and strongly attached to a home range often only a few hectares across. Individuals moved away from that range wander persistently rather than settling, so releasing a captive box turtle somewhere convenient usually kills it.

