DC residual current detection 24 volt DC
What you need is a &quot;pass through&quot; current sensor (using hall effect or fluxgate) This sensor will detect a differential DC current of 3mA , You could get more sensitivity with multiple passes through the aperture.  https://content.kemet.com/datasheets/KEM_SE0217_FG.pdf

This is a bit expensive, at $100 each, but you can buy similar &quot;open aperture&quot; or &quot;open core&quot;  or &quot;pass through&quot; sensors using hall effect sensors for ~ $20 , I used some about 12yrs ago but can't remember the part number.
Normally to measure earth leakage of a load powered from a DC supply, you would just float the supply and then connect either positive or negative or a resistive centre tap to a ground stake via a 1k resistor, and measure voltage on that.  For buried DC cables, best to put the sense resistor from positive to ground, as this minimises corrosion of the wires.
LEM make some too, e.g. CTSR 0.3P  , just put ten cores through of  each of the feed and return conductors for 30mA full scale output.

Notes:

With all of these residual current sensors you need to have the outgoing and return leads passing through the aperture, and have the same number of turns on each;
and your power supply also needs to have one terminal earthed in order to have return current,
this takes as back to what I said earlier, just measure the current through (volts across) the earthing resistor,
you won't get 40mA of current through a human who touches a 24v wire, maybe if they are standing in a bath of salt water, with wet salty hands.
if you put multiple turns through the aperture, this may limit the maximum current you can use , 16g (1.6sqmm) wire has a nominal rating of 16Amps, but if you bunch 20 odd wires together, it will get very hot long before 16Amp.
your supply has a large short circuit current, then you may need protective devices to avoid thermally damaging your current sensor during a fault.
if a high short circuit current is feasible then check the datasheet of the sensor for it's maximum ampere-turns rating.