The trick is the "memory" function of a latching relay. That is, you only need to momentarily trigger the relay to change its position and it remembers the new position even after removing the trigger (voltage). In general a latching relay has a "set" input and a "reset" input. In this example, when the trolley runs over the A insulated section, it sets the relay. When the trolley runs over the B insulated section, it resets the relay. When the trolley runs over the C insulated section, it applies power to the switch machine to toggle the direction. That is, if the trolley last hit the A section, the relay will be set to apply the C trigger to change the switch to the B position. If the trolley last hit the B section, the relay will be reset to apply the C trigger to change the switch to the A position. That is how it alternates.
What's subtle is what Elliot described in one of his posts. The latching relay is toggled when the trolley enters the A or B section. You cannot have the relay toggle from the C section. Why? Because you can get multiple triggers from dirty track!