Nor are they trespassing if they've fallen or been pushed from a station platform or overbridge, etc, their car has broken down on a level crossing, they've been involved in an RTC that has resulted in their vehicle falling down the embankment slope onto the railway, if they've been detrained onto the track by a member of staff*, they've been ejected from a train in an accident, self-evacuated from a train following an accident (e.g. to escape a fire), directed onto the railway by a person authorised to do so**, and many other scenarios that are even less likely to occur.
*I hope nobody has ever been hit by a train in these circumstances, but it is at least theoretically possible.
**I don't know whether it would be technically trespassing if the person was not authorised but the person following the directions had a reasonable belief they were so. It would be unlikely to be prosecuted in such circumstances of course regardless.