Solar panels cover great real estate to generate sufficient power.
All these are built up onto racks to keep them elevated and protect them from weeds covering them and to face in the most ideal direction toward the sun.
Once built, they still gather dust and have to be cleaned so a secondary cleaning device has to be installed on tracks so they can automatically clean the glass surfaces.
This takes additional investment, time and money.
However railroads own a lot of territory even if all we consider is the space between the tracks.
Placing solar panels between the tracts flat is not the most ideal angle but the thousands of miles of unencumbered tracks would add up to significant power generation that could be used by the trains for "green" propulsion right at the source.
And if we design a cleaning attachment to the bottom of all the trains the glass would be cleaned with the passage of every train.