An unrealistic hope or fantasy.
The allusion is to the dreams experienced by smokers of opium pipes. Opiates were widely used by the English literati in the 18th and 19th centuries. Samuel Taylor Coleridge was one of the best known users, and it would be difficult to claim that the imagery in surreal works like Kubla Khan owned nothing to opium. Lewis Carroll, although not known to be an opium user himself, makes clear allusions to drug use in Alice's Adventures in Wonderland. Sir Arthur Conan Doyle has his hero Sherlock Holmes visit an opium den - although that was for research rather than consumption.
It's strange then that 'pipe dream' comes from none of these sources but has an American origin. The early references to the phrase all originate from in or around Chicago. The earliest I have found is from The Chicago Daily Tribune, December 1890:
"It [aerial navigation] has been regarded as a pipe-dream for a good many years."
The first that associates the phrase with opium smoking is from The Fort Wayne Gazette, September 1895:
"There are things taking place every day in Chicago which are are devoid of rational explanation as the mysterious coinings of the novelist's brain. Newspaper men hear of them, but in the rush for cold, hard facts, the 'pipe stories', as queer and unexplainable stories are called, are at a discount. Were it not for this the following incident, which can be verified by the word of several reputable men, would have long ago received the space and attention it merits instead of being consigned to the wastebasket as the 'pipe dream' of an opium devotee."
[The piece goes on to describe an incredible story, apparently believed by the reporter, of a mystic incident in which a man foretells in detail the suicide of another man. It rather makes one wonder what the reporter had been smoking]
In his 1896 play, "Artie - A Story of the Streets and Town", the American columnist and playwright George Ade penned this line:
"But then I was spinnin' pipe dreams myself, tellin' about how much I lose on the board and all that."
It seems clear that that Ade would have expected his audience to have prior knowledge of it. He goes to no effort to explain it in the play and the meaning wouldn't have been clear otherwise.
See other phrases that were coined in the USA.