Are you using a BLTouch or an IR sensor?
M558 P0 X0 Y0 Z1 H3 F200 T5000 R0 ; smart IR Z probe,
That would indicate IR probe.
M307 H3 A-1 C-1 D-1 ; BLTouch
M402 ; make sure the probe is retracted
That would indicate BLTouch.
Home Z G1 Z-300 F5000 S1 ; move quickly to X axis endstop and stop there (first pass)
That would indicate an endstop switch.
M574 X2 Y2 Z0 S0 ; Define active high microswitches
Except that would indicate no Z endstop at all.
I'm not sure how this ever worked.