The Phrase Finder (as is usually the case) has an excellent explanation of the origin of this expression, which is defined to mean “A promise of heaven, while continuing to suffer in this life.” It is an American phrase coined by a leader of The Industrial Workers of the World (Wobblies) in 1911. He wrote a song titled The Preacher and the Slave that contained the line in the chorus explaining that you won’t get anything to eat now (except for hay), but “You’ll get pie in the sky when you die.”
The phrase caught on in the later stages of the Great Depression and during the Second World War and was used to “…refer to any prospect for future happiness which was unlikely ever to be realized.”