The thing with trains is twofold: First of all, it’s relatively easy to ensure that a train is more or less always hooked up to the grid (lines over the tracks). That means it can charge almost constantly, and doesn’t need a large battery.
The second thing is that the energy required to run a train scales very slowly with mass, because there is almost no rolling resistance (steel wheels on steel tracks have that advantage). That means you can increase the base weight of the train a bit without worrying about increased energy consumption.
Hydrogen can compete in applications where you need large amounts of energy, that needs to be transported, and where you don’t have regular access to the grid. Prime examples could be long-distance shipping, flight, and long-distance trucking through areas with little or no electric infrastructure (e.g. rural Australia).