You've found a popular topic. This comes up about once every two weeks. The last posting was on 3/12/23.
Below is what I posted then.
Here are several aftermarket controllers that will do reversing, most with intermediate stops. Start here:
Need help with Auto Reverse Module for Trolley (5/12/18) | Cathy C
Arduino BARC (1/7/19) | TrainElectronics.com
Z-Stuff DZ-1240 Auto Reverse & Stop Module (3/12/23) | Trainz.com
When you get a chance try out the forum Search. Type in the string "auto reverse" in the box 'Exact phrase match'. There are actually many more matches, all with good suggestions.
Mike