There are a number of animes where spirits or ghosts travel on a train. Does
anyone know the source of this? Is it from Japanese literature or a common
source?

Grave of the Fireflies: The ghosts of two children travel via train visiting
the last two months of their lives

Paranois Agent: Three characters fail at suicide and eventually they visit
far away places via a train. They do not realize that they are already
ghosts

Evangelion: Shinji during third impact (and other dream states) travels by
train with other characters who confront him. At one point, a wounded Toji
is also on the train and observes Shinji & Auska arguing.

A Chinese Ghost Story (havent seen it myself, but I found a reference to
"reincarnation train").

Spirited Away, Ghost Sweeper Mikami, Galaxy Railways - nuff said!

ten/mark