I am thinking that interfacing the 50kHz pulse outputs from the stepper driver to a relay will not work well, at least without a bit of added circuitry,
You might try this:
Reference tinyG V8 diagram
Connect a voltmeter to the ‘DIR’ pin input to the stepper driver you have programmed to be the Z axis and see if it follows “Up” and “Down” sense in a useful way as you issue G1 Z0 and G1 Z1 commands.
You may find you have to latch the sense (perhaps using the enable (active low)) pin; I’m not sure. That dir lead could then be used, with appropriate level shifter circuit, to drive your solenoid.