Not in front of my computer, but there’s another line for z min endstop inverting and another for z max endstop inverting. Check those lines too and reverse whatever logic is there. Don’t for M502 and M500 after updating firmware. Also, run M119 a number of times. Does the endstop states change randomly? If so set the endstop pull-up in the firmware to true.
Basically , when the printer first turns on and finishes the probe check, all endstop states should read OPEN or untriggered.