At best they can use some particularly suitable embankments.
Putting solar actually near the tracks is presumably not on the cards: not only because the regulations for bolting techy shit to a railway are there for a reason, but also the vibration, the overshadowed nature of much railway, thick black grime, and difficulty in getting access for maintenance, and impediment and vulnerability to normal railway maintenance. It sounds a nightmare in both operational and capital terms.
And since the trains mostly run at 25kV (the 750V third rail systems are basically a dead end in the UK) it would probably be quite a headache to step a few dozen panels here and there up to that, even if there was a way to feed it in near the panel. So exporting to the national grid is probably more cost effective in many cases.
Then again, it's understandable that if Network Rail has to have the land anyway that it wants to get something out of it rather than it just being a net cost.