Asuming the mechanical movement is free, could it be an intermittant connection to the stepper motor ?
I had a similar problem with a different make of machine. The z axis would occasionally move up and down wildly crashing the head, then it would go back to normal but be offset from its expected position.
I found the fault in the end when it acted up whilst the machine was parked and I wiggled a few connectors and it fixed it. I presume the stepper coils were energised to hold the z position, but the break in the feed to a coil caused the stepper to move 1/8th of a turn back and forth.
You might investigate a stepper coil becoming open circuit when hot, connectors dirty, or abrasion at the point the wiring passes through the arm joints.
In the PCB image, I am not certain the connectors on the right are for the steppers, so DYOR there.