So... I don't know... But my thinking is a little different. What happened is the compiler thought it was in the retract_z_probe() function. But it wasn't. It got out of sync with the code and it was missing a curly brace or a semicolon somewhere. It was reporting the error the best it could. Even though where the axis==Z_AXIS stuff was clearly outside and beyond the retract_z_probe() function to you and me... To the compiler it never closed out and finished doing the work for that function. It thought it was still in that function. So it reported that it found an error while compiling that function.
That function isn't that long, but its got all those #ifdef's in it. I don't know... My guess would be somehow those turned off a closing curly brace that was needed to close out the function and the compiler got confused.
But like I said... Short of actually seeing the code causing it to happen, and finding the fix, it is hard to say for sure. But that is kind of how my thought process works and where I would start.
Its kind of like when the compiler complains I'm missing a semicolon and tells me where it should be. If it knows where it should be, just put it there for me!!!!