Under the entry gravy, Etymonline gives:
late 14c. (early 14c. in Anglo-French), from Old French grave, graue, apparently a misspelling of grané "sauce, stew," with -n- misread for -u- -- the character used for -v- in medial positions in words in medieval manuscripts.
The French word probably originally meant "properly grained, seasoned," from Latin granum "grain, seed" (see grain (n.)). Meaning "money easily acquired" first attested 1910; gravy train (1909) originally was railroad slang for a short haul that paid well. Gravy-boat "small, deep dish for holding gravy or sauce" is from 1827.
[Etymonline]
GRAVY TRAIN - "In the 1920s, railroad men invented the express to 'ride the gravy train' to describe a run on which there was good pay and little work. The words were quickly adopted into general speech, meaning to have an easy job that pays well, or, more commonly, to be prosperous. 'Gravy,' however, had been slang for easy money since the early 1900s." From Encyclopedia of Word and Phrase Origins by Robert Hendrickson (Facts on File, New York, 1997).
[The Phrase Finder]
Regardless of whether you think of gravy as a rich meat-based tomato sauce, or, as do most Americans, as a thick brown sauce made from pan drippings, especially good with biscuits, there is no disputing that we all love our gravy. In the early twentieth century, the word gravy came to mean “easy money.” This sometimes meant easy profits resulting from just plain old good luck, but it also could refer to easy, but ill-gotten gains, especially through conning your way into it.
Gravy could also refer to any unexpected benefit, or poker winnings, and conversely, to a prison sentence, especially a harsh one, as in in the phrase “dish out the gravy” to mean deliver a harsh sentence.
When you combine gravy with train, then, you get the idea of easy money that keeps on coming in, with little effort on your part. It doesn’t stop, just like a train. We could leave it at that and feel pretty certain that we understand the origins of gravy train, but it turns out that the term actually originated with railroad workers of the 1920’s, who used it to mean an easy but high paying run.
Riding the Gravy Train
Pink Floyd used the phrase “riding the gravy train” in their song Have a Cigar, in regards to, ostensibly, record executives or other music industry hanger-owns urging the band to capitalize on the success of a previous hit for “easy money” and, perhaps, to the record company itself “getting a free ride.”
In the 1970’s, truck drivers had a similar expression. A gravy hauler was a truck driver who would only drive high-paying runs.