OP writes: Why would the timing change, other than some sort of faulty sensor?
Like you say, most likely reason would be a faulty sensor. If your car’s engine uses a knock sensor, that would be the first suspect. Next, a faulty crank position sensor. A faulty ignition system component could cause it too.
OP writes: How easy would it be to check the gap? I suppose just using a gap tool, like I used decades ago when I installed my own plugs? ?
Yes, it is done with a spark plug gap tool. It’s a simple task for a mechanic to check one spark plug. The only way to know for certain if a widened spark gap is causing your particular problem is to check all the spark plugs, and at that point you might as well replace them all with new ones. That’s more expensive of course.
OP writes: What is an EGR system malfunction?
The EGR system kicks in during heavy acceleration or high engine load (like going uphill) to keep the inside parts of the engine cool, done in part to prevent pinging. The specific way this function is implemented depends on the make/model/year, but there’s often an EGR valve involved, and those especially can malfunction by sticking closed, which prevents the desired cooling effect.
OP writes: And if it were a major mechanical fault with the engine, what might this be? .
Carbon deposits forming inside the combustion chamber can cause pinging. Lean operation due to valve or injector problems is another possibility.