This is as far as I got on layman speculation. Different regions of a country presumably have different power plants feeding them, so either:
* There’s a changeover at regional boundaries where the train coasts under a short gap with no overhead line, so every section of a line is on a different power source (meaning load changes depending on how many trains are in the region);
* Each line is treated as one discrete circuit isolated at junctions, with one or multiple power plants feeding it (load is more stable but needs to be balanced between the plants);
* Every line is connected to every other line in one national or international grid, meaning load has to be very carefully managed both on the trains’ power units, and at the links to the power plants, and presumably lines have to be able to be isolated in the event of some freak accident to avoid it bringing down every train nationwide.
Most of the time, the overhead line is accompanied by one or more phases (since most power grids are three phase, that is the number that makes the most sense for railroad overhead as well) that hangs a bit to the side, so that the overhead line can occasionally switch over to one of the other phases.
This means that you need an occasional “buffer zone” where the overhead line is insulated and without power. Around here, such buffer zone are the entire length of the distance between two poles, and the poles are very obviously marked so that the train driver can easily see that right there is a pretty bad place to come to a standstill. (A train that stops where the overhead is powerless would need another train to come in and push it out of there so that it gets power, which can be easy if the pushing train got it’s own pantographs at the other end of the train set and difficult if it got it in an end that would in the process of pushing ALSO become powerless.)
For that reason, the theoretical idea you are introducing here just ain’t true. The overhead has these buffers occasionally, and the only thing you need to do when the power starts coming from the north instead of from the south, is to put up one more buffer zone and make sure that the feed from the north is reliable.
Each section of the overhead can be fed from an entirely different power company, the sections can be of varied length (and typically ARE of varied length depending on the likely power consumption in each section at a given time; a longer track with less traffic typically has longer sections than what happens in a congested piece of track right outside a major city.) and each feed point is responsible for ensuring that it’s own section(s) are properly powered.
TL:DR; electrically speaking, it’s a lot of small islands that have individual power feeds. There is no need to do any delicate balancing since all that matters is that the voltage difference between two neighbouring islands is not too high.