The transformer supplies HOT and RETURN. (some call it GROUND, which is not quite accurate, but for ease in understanding, we will call it GROUND.) An energized track has HOT on the middle rail, and GROUND on both outer rails. If you insulate a section or two of outer rail on one side, it will become grounded only when a train goes by, by the action of the wheels bridging the two outer rails. It is this ground activation that we use to activate a simple (on-off) accessory, such as a gateman, or semaphore. The other terminal of the signal must have constant HOT connected to it, from the same transformer or another transformer that is in phase with the track supply transformer. The HOT waiting on the signal must use the same ground that the track supply uses.
In a simple example, using a traditional ZW transformer, you would use the A and U posts for the track supply, and you would use the B post, set at 14 volts, to activate the accessory. The track and the accessory both share a common ground return.
For a signal that has two "ON" states, such as a block signal like the 153, a relay performs the switching of the two ON states.
The relay at rest (no electricity to its coil) supplies power to the green lamp, through its normally-on contact, and when activated, switches power off the green lamp and switches power to the red lamp through its normally-off contact.
The insulated rail activates the coil of the relay, in the same way that it would activate a simple accessory.
The relay takes the place of the 153C contactor, which is a weight-activated device. It works OK, but using a relay is much more reliable and trouble-free.
As the train go past the insulated rail section, the relay coil returns to its normal (de-energized) condition, and the red lamp goes out, and the green lamp comes on.
This scheme has been discussed many times on this and other forums. It is described in a wiring schematic in the Lionel operator's manual, too.