1. Opium smoking: In the 19th century, opium smoking was common, and the dreamy state it induced was often associated with unrealistic or fanciful thoughts.
2. Smoking pipes: The act of smoking a pipe itself can be a relaxing and contemplative activity, which can lead to daydreaming or fantasizing about things that are unlikely to happen.
The first recorded use of "pipe dream" in print was in 1887, in a story called "The Pipe Dream" by American author John Kendrick Bangs.
While the exact origin remains uncertain, the combination of these two sources and the association of pipe smoking with dreamy or unrealistic thoughts likely contributed to the development of the idiom.