Here is a circuit I believe should work. It is about as simple as I can make it.
Assuming the target has stopped somewhere mid travel at last switch off.
Each relay is latched by a NC contact in the opposite relay. As both are idle they will both attempt to energise. The fastest one should win and for this exercise assume Relay 1. This will latch ON via a NC contact in Relay 2. Also 5V is applied to comparator OP1a + input and output of OP1a will go HIGH and applied to IN? to drive the motor. I have included a momentary push button switch labeled “Start” in case this does not happen. Pressing this should force Relay 1 operation and start the sequence.
As the Target reaches Sensor 2 this will activate and activate Relay 2. The NC latching contact opens and releases Relay 1, switches OP1a so taking N? LOW. Relay 2 switches 5V to OP1b via a delay of about 0.5sec then switches the other IN? HIGH driving the motor in the other direction.
When the Target reaches Sensor 1 the process repeats by activating Relay1, releasing relay 2 OP1b output LOW and OP1a output HIGH after delay.
Delay: This is provided by R2/C1, R4/C2 and with the current component values will provide a fraction less than 0.5sec during which time both IN? driver inputs will be LOW and the motor in Braking mode. This should allow the motor to stop before reverse voltage applied which may not be catered for on the motor driver board.
The timing is set by the reference divider R5/R6 and R7/R8 providing a little over 60% of 5V which is conveniently about 1 time constant of the R2/C! and R4/C2 timing combination. If this time is not sufficient or needs to be extended increase the value of C1 and C2. Increasing the value will extend the time. This can be calculated by tSeconds = MΩ * µF or in this case 0.051 * µF.
D1/R1 and D2/R3 form a fast discharge path for the caps by bypassing the 51k resistors.
R9 and R10 provide a few mV of hysteresis to prevent any uncertainty or chatter during switching time and thus a faster, cleaner switched output.
C1 and C2 for timing purposes should be Tag Tantalum types as Tantalum caps will have a better chance of being full value at switch on. “Ordinary” electrolytic need some time to “form” to reach their full value.
C3 (100n) should be fitted as close to the LM393 as possible, even soldered to the pins on the back of the IC if necessary.
Relays. Be a bit careful here, low (5V) voltage types tend to be a bit heavy on current and the sensors can only sink 100mA (Data on Jaycar site) so you may need to use 12V types. The Sensor data says 5V operating voltage but that applies to the internal electronics. The NPN output collector is completely independent of this and should be OK with 12V. This sort of thing can generally handle up to 24,36 or even 48V but unfortunately the data for this unit is very thin as is most of these things these days. You can get others which do have data available but you have to pay a few dollars for those.
If a relay less than 100mA cannot be found you will have to interface another transistor to drive each relay.
Here is a limit switch circuit I have posted before elsewhere.
This sort of thing should be completely separated from any electronic driver circuits.
It is POLARITY SENSITIVE as it provides a braking diode to stop the motor dead and prevent damage due to over run. Also “steering” diodes to allow reversing the motor off the switch which at this point is open removing voltage from the motor.
Diodes should be 20A rated. Usually found in dual 10A packages either common cathode or common anode. Just join the 2 in parallel.
Don’t forget. If using this circuit BE CAREFUL of polarity.