If you have arrived at Glenfinnan by train, then the return one cannot be cancelled because it is the same 4 car train making the return journey..
If it broke down at Mallaiig then Scotrail have a legal requirement to provide alternative transport on two counts - a. The delay would be over one hour, b. It is the last Scotrail train of the day beyond Fort William. In extremis, if unable to source taxis or buses, then they might put passengers on the sleeper train (the only one in Scotland to take local seated passengers) or else they would have to find hotel rooms.
If you just went and found other transport you would be unable to recover your costs. Use the help points in the miniscule possibility that happens.
Honestly the chance of your being stranded by the train is so remote that it can be discounted.
If this week's Jacobite replacement charters become regular the hordes of people may be back as they have been hauled by a pair of Class 37 diesel engines- a treat to many rail fans.
PS- The fact that it is currently a 4 car train also provides redundancy. If one half failed at Mallaig they would dump the failed unit and run the other half back. But one unit can haul a dead unit anyway, at reduced speed.