This long piece of steel bar is linked to the lever that operates a set of switch points. It sits just inside the rail and is slightly longer than the maximum distance between any two axles on a car. When the switch is operated, the bar must rise above the rail head. If a train is passing over, the wheel flanges block the bar from rising, physically locking the switch in place until the track is clear.
The lever won't budge because the detector bar is pinned down by that last hopper.
Track circuits have largely replaced these mechanical bars, but you will still find them protecting switches in older manual interlocking plants.
Related terms
Switch points
The pair of movable, tapered rails in a turnout that steer wheels onto one route or the other.
Interlocking
An arrangement of signals and switches interconnected to prevent conflicting train movements.
Track circuit
A low-voltage electrical circuit running through the rails to detect the presence of a train.