Z-Axis Seems to Reprogram Itself

Which machine/Z-axis do you have?

Is all the wiring in good condition and all connectors secure?

Is the machine mechanically sound, well-adjuted, and if applicable well-lubricated?

Which sort of probing are you using? See:

and

https://carbide3d.com/blog/unexpected-z-axis-plunges/

If you continue to have difficulties, post a .c2d file, step-by-step notes on how you are securing your stock and setting zero relative to it and managing all tool changes.