late 14c., "full of joy, merry; light-hearted, carefree;" also "wanton, lewd, lascivious" (late 12c. as a surname, Philippus de Gay), from Old French gai "joyful, happy; pleasant, agreeably charming; forward, pert" (12c.; cf. Old Spanish gayo, Portuguese gaio, Italian gajo, probably French loan-words). Ultimate origin disputed; perhaps from Frankish *gahi (cf. Old High German wahi "pretty"), though not all etymologists accept this. Meaning "stately and beautiful; splendid and showily dressed" is from early 14c. The word gay by the 1890s had an overall tinge of promiscuity -- a gay house was a brothel. The suggestion of immorality in the word can be traced back at least to the 1630s, if not to Chaucer:
Slang meaning "homosexual" (adj.) begins to appear in psychological writing late 1940s, evidently picked up from gay slang and not always easily distinguished from the older sense:
The association with (male) homosexuality likely got a boost from the term gay cat, used as far back as 1893 in American English for "young hobo," one who is new on the road, also one who sometimes does jobs.
Quoting a tramp named Frenchy, who might not have known the origin. Gay cats were severely and cruelly abused by "real" tramps and bums, who considered them "an inferior order of beings who begs of and otherwise preys upon the bum -- as it were a jackal following up the king of beasts" [Prof. John J. McCook, "Tramps," in "The Public Treatment of Pauperism," 1893], but some accounts report certain older tramps would dominate a gay cat and employ him as a sort of slave. In "Sociology and Social Research" (1932-33) a paragraph on the "gay cat" phenomenon notes, "Homosexual practices are more common than rare in this group," and gey cat "homosexual boy" is attested in N. Erskine's 1933 dictionary of "Underworld & Prison Slang" (gey is a Scottish variant of gay).
The "Dictionary of American Slang" reports that gay (adj.) was used by homosexuals, among themselves, in this sense since at least 1920. Rawson ["Wicked Words"] notes a male prostitute using gay in reference to male homosexuals (but also to female prostitutes) in London's notorious Cleveland Street Scandal of 1889. Ayto ["20th Century Words"] calls attention to the ambiguous use of the word in the 1868 song "The Gay Young Clerk in the Dry Goods Store," by U.S. female impersonator Will S. Hays, but the word evidently was not popularly felt in this sense by wider society until the 1950s at the earliest.
Gay as a noun meaning "a (usually male) homosexual" is attested from 1971; in Middle English it meant "excellent person, noble lady, gallant knight," also "something gay or bright; an ornament or badge" (c.1400). As a slang word meaning "bad, inferior, undesirable," from 2000.