I never gave thought about its origin before, but I was reading about, oddly enough, contemplative prayer The Cloud of Unknowing) and a reference was made to cloud nine as something from Buddhism.
I have to say that my own associations with the term are more with the "psychedelic soul" song, "Cloud Nine," by The Temptations and the Cloud 9 album by George Harrison.
Looking for the etymology, I found most frequently references to Buddhism and to the study of clouds.
There is an actual (but old) International Cloud Atlas which defines types of cloud. (Not to be confused with Cloud Atlas: A Novel and the film version of the novel - both of which befuddled me.) The atlas defines the ninth cloud as the cumulonimbus, which rises to 10 km (6.2 miles), the highest a cloud can be.
In Buddhism, it supposedly is a reference to the state of being that is the penultimate goal of the Bhodisattva.
A flaw in both these origins is that there are ten stages in the progress of the Bodhisattva, and there are actually ten levels of clouds.
Another reference is to in Dante's Paradise section of the Divine Comedy where the 9th level of heaven is closest to the Divine Presence, which itself dwells at the 10th and highest heaven.
In all three instances 9 is not the top.
Another pop culture reference I found is to a 1950s radio show called "Johnny Dollar" in which every time the hero was knocked unconscious he was transported to Cloud Nine. The 1950s fits in with the Cloud Atlas of that period, but there are earlier references to cloud nine.
I suppose that if the old atlas only had 9 levels, that may have influenced the usage. I can think of other "nine" references in our popular usage where the nine seems an odd choice. There is the 'whole nine yards' in American Football, where it is ten yards rather than nine that is a significant measure for a first down. And we also say someone is "dressed to the nines" as being very fancily dressed.
It seems that even earlier the phrase "head in the clouds" to mean a kind of dreaminess, induced by either intoxication or inspiration, was used. A 1935 directory of slang, The Underworld Speaks, gives the examples of "Cloud eight, befuddled on account of drinking too much liquor."
The Dictionary of American Slang (1960) might be the first printed definition of the term cloud nine as we use. At that point in time, the term had close association with the euphoria that is induced by alcohol and drugs.