Since humans are upright and scan the horizon it makes sense for flags to have wide orientation and horizontal stripes.
A train has no need to scan the horizon since they live on a track and are not upright.
It therefore would be more visually appealing to the senses of a train for them to visually oriented for a taller than it is wide flag with vertical stripes.
My theory: