Nobody may read this, but here was my experience with, I think, a similar problem.
The Z limit switch (first axis homed) appeared to work fine when I put an ohm meter on it and depress it with my finger. However, if I depress the switch until it clicks but not any further, the closed/open state is not reliable. The resistance across the switch is highly variable when it is closed but almost open.
When homing, the machine travels to the switch, closes it, reverses direction until it opens, then stops. The machine is in the unreliable position (after the click but no further) when it stops to reverse. Sometimes a false open resistance causes the machine to stop before it travels back far enough to fully open the switch. Other times the resistance is such that the machine continues with homing but eventually the cnc senses it as closed and shuts down due to a limit error. This can occur anytime while the other axes are homing until the gantry is moved away from the switch causing it to fully open. The randomness of the problem made it hard to troubleshoot.
Put an ohm meter on the limit switch and depress it very slowly. Stop as soon as it clicks and see if it is truly changes state and holds it. Going the other way, fully depress the switch and slowly release it to see if the resistance changes prior to the click.