Joris-Karl Huysmans, a prominent French novelist of the fin-de-siècle wrote in Certains (1889) wrote (trans. Richard Lane, ):
The most beautiful Japanese erotic print that I know is truly frightening: it is of a Japanese woman mounted by an octopus; with its tentacles, the horrible beast sucks the tips of her breasts and rummages in her mouth, while its head drinks from her lower parts. The almost superhuman expression of agony and sorrow - which convulses this long, graceful female figure with aquiline nose - and the hysterical joy - which emanates at the same time from her forehead, from those eyes closed as in death - are admirable.
This is a description of Tako no Ama ("Diver and Octopi") by Hokusai Katsushika (1760-1864), the famous ukiyo-e etching which is more popularly known in English-speaking countries as "The Dream of the Fisherman's Wife", which was first published in Kinoe no komatsu (1814). It is the ur-example that most people think of when they consider Japanese tentacle erotica...but it is not the beginning of the story.
Danielle Talerico in "Interpreting Sexual Imagery in Japanese Prints: A Fresh Approach to Hokusai's Diver and Two Octopi" in Impressions: The Journal of the Ukiyo-e Society of America #23 (2001) traces Hokusai's imagery as part of a tradition in Japanese art:
Hokusai's contemporary audience would have viewed his illustration quite differently from Huysmans, Goncourt, and subsequent generations of Western connoisseurs. They would have recognized the origns of the scene in the ancient folktale Taishokan ("The Great Woven Cap"). Taishokan derives from a title bestowed upon a person who held the highest rank at court, and it became the epithet for the seventh-century courtier Fujiwara no Kamatari, who was well known by this name. It was not unusual for ukiyo-e to parody popular literature [...] Taishokan is the dramatic story of a diving woman who retrieves a precious gem from the Dragon King of the Sea. It is essentially a Buddhist moral tale. [...] Taishokan has a long literary history and several variants of the tale exist. The earliest dates to the fourteenth century and is found in Legends Surrounding the Founding of Shido Temple (Shidoji engi). This version of the tale is the source of the popular Noh drama Ama (Diver) by Zeami (1363-1443). Between the fifteenth and nineteenth centuries ballad-dramas known as kowaka-mai, dramatic chanting associated with Bunraku called joruri, and theatrical Kabuki versions of Taishokan were performed for Edo audiences. Not surprisingly, ukiyo-e artists capitalized on teh tale's dramatic and literary popularity, and the story became a common print theme from the early Edo period onward. Early Edo-period ukiyo-e illustrations draw on the ballad-drama version of Taishokan.
The original story and the play did not depict the diver in a sexualized way, and the octopus was one of the Dragon King's servants sent to capture her. Over a period of decades, a combination of government censorship and artistic efforts to skirt that censorship gave way to "risky pictures" (abuna-e), commonly featuring nude female divers:
The sexualization of the abalone diver was also encouraged by terms connecting sex with water: mizu shobai ("water trade," or prostitution), mizu age ("sexual initiation"), and mizusho (a wanton woman) to name a few. Many ukiyo-e artists created sexually explicit prints featuring water and sex.
The octopus comes into these erotic diver prints in the 1700s, with one particularly evocative work by Katsukawa Shunsho (1725-1792).
Following Shunsho several artists exceeded the bounds of "risky pictures" in sexually explicit diver and octopus imagery; the multiple appendages of the octopus take on a phallic character, performing penetration and cunnilingus. [...] Kitao Shigemasa (1739-1820) seems to be the first to directly link sexually explicit diver and octopus imagery to the Tamatori story. His rendition is a sexual parody of the Noh play Ama and a visual pun on early Tamatori-tale imagery.
Hokusai was a student of Shunso, and Hokusai's Tako no ama, published in 1814, is actually a throwback to this older erotic motif, what Talerico calls "the last-known Edo-period sexual image of a diving woman and an octopus." So how did it end up giving Huysmans the chills in France?
Ricardo Bru in Erotic Japonisme: The Influence of Japanese Sexual Imagery on Western Art describes sporadic encounters between Westerners and erotic Japanese art, and there was a limited trade in erotic art with Westerners in Japan into the 19th century - the "opening of Japan" in 1853 meant there were suddenly a lot more Westerners, and hence more exposure to the material.
[...] the first European merchants settling in Yokohama and KObe began to export ukiyo-e (including erotic prints), which they sold directly to the many outlets springing up in major European and American cities, in particular, Paris. The latter was the first center of Japonisme in Europe and the location of some of the best collections of shunga that were assembled from around 1880 to 1910.
"Japonisme" was a European art movement inspired by Japanese prints, including erotic prints. Hokusai's erotic work arrived in France at an auspicious time:
The arrive of Pine Seedlings on the First Rat Day in France roughly coincided with Victor HUgo's (1802-1885) romantic novel Toilers of the Sea (Les travailleurs de la mer, 1866), in which one of the protagonists was a terrorizing octopus (pieuvre). This creature was based on popular European folktales also employed later by Jules Verne in his Twenty Thousand Leaues Under the Sea (Vingt mille lieus sous les mers, 1869-1870). [...] The release of Hugo's and Verne's works occurred at precisely the moment when Hokusai was discovered and applauded as one of the greatest Japanese artists--it was at this time that the first Japanese prints featuring erotic or frightening octopuses arrived in the West.
Many Western artists would be inspired by the erotic octopus prints of Hokusai and others, including Pablo Picasso--for more on which, see Secret Images: Picasso and the Japanese Erotic Print--and this formed the core of the reputation for Japanese tentacle erotica around the late-19th century in the West, and by its influence inspired a lot of tentacle erotica in Western art.
But that's not the whole story. The contemporary reputation for tentacle erotica in Japan traces to the Toshio Maeda's Urotsukidōji and Demon Beast Invasion anime (manga 1986, anime 1990), when Japanese manga artists were struggling with government censorship. In an interview, Toshio Maeda says:
At that time [pre-Urotsuki Doji], it was illegal to create a sensual scene in bed. I thought I should do something to avoid drawing such a normal sensual scene. So I just created a creature. [His tentacle] is not a [penis] as a pretext. I could say, as an excuse, this is not a [penis], this is just a part of the creature. You know, the creatures, they don't have a gender. A creature is a creature. So it is not obscene - not illegal.
Drawing intercourse was, and is, illegal in Japan. That is our big headache: to create such a sensual scene. We are always using any type of trick.
The idea of penetrative tentacle sex in comic art was not unique to Japanese manga of the period (a Western example is “Love in Arms” by Bob Lee and Brad W. Foster in the comic Fever Pitch (1988), where a woman imagines penetrative sex with an octopus.) However, the idea did not really catch on in the US until the concept was imported by Japanese erotic anime such as La Blue Girl (1993) - which was also based on a Maeda manga. Limited availability of titles in European and American markets helped push a somewhat skewed image of Japanese eroticism - because titles like La Blue Girl and Demon Beast Invasion were made fairly widely available, they helped cement the reputation for "tentacle sex" as a Japanese convention (and, to be fair, artistically it is now very much a trope, over and beyond Maeda's original purpose of skirting censorship limitations). The Erotic Anime Movie Guide section "Tits and Tentacles" explains:
The visual grammer permitted by the tentacle is extremely useful to the pornographer. With no restriction on length, it permits penetration without blocking the view. It can also be used as a form of restraint, permiting multiple penetration, sexualised bondage and east of access. Best of all for the tentacle as a pornographic device, while it may often look suspiciously like a penis, to the extent of possessing a foreskin or glans, or even ejaculating upon climax, it is not a sexual organ by definition.
Which I hope answers your question.