When a train runs onto the track, thus connecting the two rails, a short circuit is created, the current drops out and the signal switched to red. The system operates in conjunction with a lever on the tracks. If a train should pass a red light, the lever, which is called a tripcock, comes into play. The tripcock releases the air from the train's air-braking system, thus causing the brakes to come on and stopping the train.
Source: wiktionary