I’ve had similar problems on the Z-axis of my Mendel Prusa i3. They would run in parallel most of the time but would occasionally run amok in different directions. It turned out to be a dicey RAMBo pin to PCB solder joint (the RAMBo has separate connectors for the two Z motors.) I’m 95% sure you have a similar “air gap” in a wire or maybe a cold solder joint. I’d try replacing all the cables and redoing all solder joints. It could even be a broken conductor in a cable that sparks/connects intermittently. One last idea: are the stepper conductors and the end-stop conductors sharing a cable anywhere (in the same sheath?) I’d keep them apart and separated physically by a few inches at least The current flow to ground when a NO end-stop closes might bother the stepper pulse signaling?