3 part mechanical joint following 1 bone?
Dissolve the middle bone (you just need two bones for your rig). the first bone's constraint wouldn't be changed. for the second bone set world space to world space.

if you want the hinge to be oriented as you wish do above works and add another bone called hinge and make it child of your z bone. assign a locked track constraint to it and set either tail of ctrl or last deforming tail as the target and also set y as the locked axis and -z as the following axis. the result is like below.