Attaching your code was helpful.... I'm not sure what you are seeing. But I would try a couple of things to debug it. First, I would get it into a state where it isn't moving properly. And then I would give it an M119 command to see what it thinks the state of the end stops is. It may be possible you have bad wiring or switches. If this fails to show anything that might be helpful, I think I would try rebuilding the firmware with a few changes. For starters, I think I would change:
Code:
#ifdef ENDSTOPPULLUPS
  //#define ENDSTOPPULLUP_XMAX
  #define ENDSTOPPULLUP_YMAX
  //#define ENDSTOPPULLUP_ZMAX
  #define ENDSTOPPULLUP_XMIN
  //#define ENDSTOPPULLUP_YMIN
  #define ENDSTOPPULLUP_ZMIN
#endif
to:

Code:
#ifdef ENDSTOPPULLUPS
  #define ENDSTOPPULLUP_XMAX
  #define ENDSTOPPULLUP_YMAX
  #define ENDSTOPPULLUP_ZMAX
  #define ENDSTOPPULLUP_XMIN
  #define ENDSTOPPULLUP_YMIN
  #define ENDSTOPPULLUP_ZMIN
#endif
Just to make sure everything has pull up voltage to it to eliminate noise. You won't hurt anything by doing this if nothing is connected to those pins. I would then repeat the above stuff to get the printer into a mode where it doesn't move correctly and try to give it another M119 to see what it thinks of the world.

Probably, I would try rebuilding the firmware with these changes to eliminate the suppression of moves when the printer thinks the endstops are being touched. This is kind of brute force, but if these changes make a difference, that will be confirmation we are dealing with an endstop switch stopping the movements:

Code:
#define min_software_endstops false  // If true, axis won't move to coordinates less than HOME_POS.
#define max_software_endstops false  // If true, axis won't move to coordinates greater than the defined lengths below.

#define DISABLE_MAX_ENDSTOPS
#define DISABLE_MIN_ENDSTOPS


//  #define Z_SAFE_HOMING   // This feature is meant to avoid Z homing with probe outside the bed area.