However, the redoubtable World Wide Words remains somewhat uncertain about the origins of the idiom.
The experts do generally agree that the phrase has its source in the slang use of gravy for something easy or cushy, simple to do, or an unexpected benefit. This is recorded in the major references books as appearing slightly earlier (1910) than gravy train (1914). As a result of the digitisation of old newspapers in very recent times, I can take these dates back somewhat. For example, advice to potential advertisers appeared in The Daily Independent of Monessen, Pennsylvania, in October 1906: “If you buy right and then tell an exacting public in a clear, concise way, just as you would over your counter, you are then getting in line for good gravy.”
There is some slight evidence that gravy goes back rather further than that. If it is the source of gravy train, it would have to, because I found the latter in the Courier of Connellsville (also in Pennsylvania) in November 1895, almost two decades before the previously oldest known example: “Johnston claims that Reuben Nelson and another tall negro were in New Haven the night of the escape and that they broke into the lockup. Johnson further states that the next day Kelson laughingly told him that the New Haven lockup was ‘a gravy train.’”
But why and how do trains come into the picture? We don’t know, which leaves the matter in an uncertain and unsatisfactory state.