You either know a lot less than me or you know more and understand it better. I honestly can't tell : )
It feeks like my brain collapses just from starting to think about thousands of kilometers of grid, thousands of power stations, millions of consumers etc. (Not that the amount of them matters, just the supply or demand they deliver/drive.)
In the interest of learning, here is my model that I map the things I do understand to:
The way I (as a hardware/software engineer who started in electronics and had a brief course on power electrics) reason about it is torque, as if they are kind of sharing a common shaft and applying torque to it while consumers are braking it.
This simplified mental model would explain - kind of - how it can stay in sync, only in reality we are talking not a linear axle or shaft but this continent-wide grid where gigawatts of supply and demand can occur within minutes or even less and the phase differs by quite a lot over the span of the continent. (In my mental model this is the axle twisting.)
Also at 50Hz the wavelength of light in vacuum should be around 6000km if I typed correctly and DDG understood correctly. A rule of thumb we learned (in high frequency electronics back in electronics engineering) was that once you cross a tenth of that the normal rules doesn't quite apply. If this can be applied to power grids (an I think it can) it becomes even more complex I guess. (The simplification we can apply in "small" circuits is that we can pretend evey point in the circuit is at the same point of the phase at the same time.)
Keep in mind everyone: these are just my models. I'll be delighted if littlesymaar (or someone else) knows this extremely well and manages to enlighten me because it would be fun to really "get" it.
Edits: A lot.
Also: Just operating one power plant can be complex: I remember one presentation from former students or something about how important it was in Eastern Europe back then to be ready to cut immediately if neighbouring plants failed or cut so that your plant wouldn't suddenly oversupply and burn out.