@dc42 So the problem is indeed that the endstop wires runs in the same wire bundle as the motor. I have temporarly solved the issue with low pass filter with cut off frequency 1Khz.
I'm currently working on having expansion boards and D-Sub cables which should ease my assembly of the Pick and Place machine. I will address this issue in the new revision of the cableing.
I'm deeply sorry for my lousy cableing which caused so much trouble. I wasn't expecting this issue because both two steppers didn't caused the issue.
Thank you very much for helping me find the issue in my machine.