The suuply is reversed by a double pole changeover switch, one changeover for each leg. For automatic operation, this switch can be a relay, that is in turn operated by a timer device. If there is significant power involved it is important to make sure the contacts break well before the other pole makes in the changeover. That is, a dead zone. With motors, you might need to stop the motor before reversing it.
A solid state switch that does the same is a H bridge. The circuit is wired like the letter H with electronic switches on each leg (4 of them) and the load on the horizontal of the H. One diagonal pair is on for one direction, and the other pair for the other direction. This is commonly used for reversing DC motors. There also needs to be a dead zone between switching one pair off (so all 4 are off) then switching on the other pair.
A timer can be mechanical or electronic. Mechanical timers have a motor driving a disk with pegs that operate the switch. Electronic timers for times longer than a few seconds are often a counter that counts the frequency of an oscillator etc, timing out when a specific count is reached. For shorter times from a few microseconds to a few seconds a 555 timer device might do.
The timer may be triggered by some event (the power came on, something pressed a button) or even by itself so the reversal is repeated over and over in a loop. This needs specific circuitry for the application.
Look up relays, H bridge, 555 timer circuits to learn more.