Because railways cut through the landscape and cameras don’t. Lots of people get up and protest against plans to put a railway through their neighbourhood. For safety it needs to be completely fenced off, otherwise the speed of the train needs to be heavily reduced through that area.
A fenced off section of track is a completely impassable barrier to pedestrians that needs expensive accommodation (bridges or tunnels) to get around.