With an engine going around a loop and back into the track you came from, the polarity for DCC (or DC) must be matched for direction.
Although the main track polarity never changes, the loop back causes the outside rail to become the inside rail going in the opposite direction. This would cause a short if connected. The only way to correct this is to isolate part of the track in the loop. This length needs to be engine (+tender) long or as long as a lighted passenger train.
Both rails of this section needs to be isolated and at both ends.
A double pole switch supplies the isolated track with one pair of polarities on the up switch and the opposite track polarities on the down switch.
Just before entering isolated track, the switch is moved to the position to match that track.
Before leaving the isolated track, the switch is moved to the position of the return track.
The switch can be replaced (recommended) with an automatic electronic reverser. Then you don't have to do anything before running your engine around.