It is illegal for pedestrians to be on a motorway, but everyone seems to recognise that in extreme times this rule can be broken - certainly no-one seems to advocate arresting people who've got out of their cars when stranded. Yet when the same thing happens on the railway, some people here don't seem to have the same understanding; indeed one post has hinted at charging them with trespass on the railway.
Yes, pedestrians are forbidden from walking on the motorway in normal circumstances, but in many emergencies it is generally expected that drivers and passengers will, especially if the carriageway is blocked and/or people are taking actions for their own safety. Most people are also much more aware of road safety than line safety, and are more familiar with driving a road vehicle.
However, any (potentially) electrified railway where most people will be wholly unfamiliar with the many, many hazards is rather more dangerous than a motorway full of stranded vehicles at a standstill.
Out of interest, did you know, for example, that the Highways Agency are only permitted to travel at 20mph on the hard shoulder when adjacent vehicles are stationary, and, despite appearances, most emergency services' vehicles don't actually travel all that much faster, especially in bad weather? Rescue locomotives may be travelling faster and take longer to stop, plus the driver is less likely to expect pedestrians and will be unable to swerve to avoid them. Also, it is easier to seek refuge to the side of a motorway, whereas many railways have multiple "Limited Clearance" areas and the like, plus tougher surfaces to walk on and a great number of trip hazards.