I don't know your CNC machine, but I'd look for loose mechanical connection between Z axis motor and ballscrew or pinion gear. If not check for binding, lack of lubrication on Z axis bearings. There could be an intermittent connection to the Z axis motor, have you checked the connector and wiring? To check for Z binding, loose mechanicals I'd write a small G-code program that just moved the Z up and down repeatedly.
CAMaster Stinger 1
Shopbot PRT 9648