Suppose you wanted to run a normal electric train up a mountain. It would certainly take a decent amount of power but not so much that it would be a big challenge for a city-scale power grid. So far you're not yet talking the scale of power where storing it would really be interesting to a grid.
One option to store more power would be to make the train much, much heavier. Sounds simple enough -- fill all of the cars with concrete and now hauling it up the mountain will store a lot more power. However now the rails and the trains themselves will need to be far sturdier than a normal railway, and will wear out quickly.
The other option will be to simply scale up -- start the day with a hundred trains in a rail yard at the bottom of the mountain and over the course of a day move them all to a rail yard at the top. Now you have successfully stored a decent amount of juice.
But hold on a minute... you've now built two large rail yards, meaning you'll need a lot of relatively flat real estate at both altitudes. How about instead you just dig a hole on each side, called it a reservoir, and put a pipe between the two? Certainly it must be a lot easier to store and move mass in the form of water than it is in the form of trains!
That is why I don't see much potential in rail-based storage: if you have the geography to build one at-scale, probably you could build pumped hydro there cheaper. Even if you were in a water-scarce area where you would need to enclose both reservoirs to avoid evaporation loss it still sounds simpler to me than building and maintaining a hundred heavy trains would be. Also, routing a pipe between two reservoirs is a lot more flexible than building a railway.
In my head it still seems like it would be cheaper than digging out massive reservoirs for pumped hydro. Rail seems relatively cheap even if you do have to replace it regularly because of the wear. It also seems like you could put the rail in all sorts of geographies, big and small. Maybe it isn't worth it unless you go big though... and at that point why not hydro.
It's good questions though. No idea how the economics of it will work out vs pumped hydro.
Then collected money could eventually pay off the cost of construction, and eventually maybe even offset the maintenance cost.
If nothing else, it would certainly boast the advantage of being more fun than water storage.
You run the trains up the hill when energy is cheap or, for example, when the sun is out and solar works. Then when you need it, you run the trains down hill to generate electricity. Similar to pumped hydro where they do the same by pumping water up hill and then draining it downhill later. Super cool!