Yes the WDW Railroad has different hours than the park... Here is how they determine when it closes and then you can look at your day and see which applies to you... there are 3 scenerios:
First scenerio... NO FIREWORKS...this rarely happens anymore, trains will run until park close, with the last train leaving main street AT park closing time.
Second scenerio... FIREWORKS are AT park closing time (example park closes at 8, fireworks start at 8)... The last train will leave Main Street at 7 (ONE hours prior to fireworks and will then be closed for the night)...
Third Scenerio...there are fireworks but they are not AT park closing (example. The fireworks are at 8 but the park does not close until 9) in this case the last train that is going ALL the way around tha park and back to Main Street will leave Main Street at 7:20 and do one full loop back to Main Street and exit everyone there...the other train will leave main street at 7:30 and stop only at Fronteirland and Toon Town and will stay at Toon Town until after the fireworks... once the fireworks are done (and the fire marshall clears the track) the trains will begin running again until the official park closing time. In this scenerio the last train ride is 40 minutes (if wanting to go back to main street) 30 minutes (if trying to get to the back of the park) before the listed fireworks start time.
(and non of these scenerios apply to night when there is Grad Night, Night of Joy or other after hours events...as they bring equipment and wires across the tracks and require the trains to close at 4pm... which would obviously not apply to you since you are trying to escape Spectro, but in case anyone else is reading...Just FYI)
The back area of the train tracks between Frontierland and Toon Town is the firework fall out area and the trains can not be running for safety reasons...
If you have any specific question and or did not understand one of the scenerios please feel free to ask... I work on the train