You really need to include what brand of firmware you are using or find the specific forum section for it.
I am going to assume you're using Marlin as that's an issue, however it should only flash 3 * Z height like that for a split second.
The printer should also stop at any point an endstop is triggered, they should never be disabled by anything. It sounds like maybe the firmware is bugged. Check for a new version and upload a fresh copy and see if it still has issues.