Z Axis under the table?

I kinda guessed that. You’re using G28 retracts (usually a checkbox option when you post process) which adds this line to your gcode:
G28 G91 Z0

There’s a decent chance that your g28 location is the issue. I’d recommend unchecking that box.

G28 G91 Z0 Moves the Z axis only to your G28 location. If you have never explicitly set a G28 position (using G28.1), then that position, by default is at Machine 0 (your homing switches). I’ve seen this many times with cnc users. The Z crashes on that move and Z-zero is lost.

What post processor are you using?
Do you have homing switches?