I've managed to loosen the wires from the terminal and place them in a correct way using a flat screwdriver that came with the other Ender 3 tools. After switching wires to correct position the z axis started to autohome correctly and z stop switch started working correctly. In the case of only the Z-axis of your Ender 3 failing to home, we can immediately tell that the Z-axis endstop is the culprit, meaning that either there are problems with its wiring (especially likely if you have been working on your Ender 3 lately) or the endstop switch is not functional anymore. cOdX0.

ender 3 z axis not homing