The term means "to be happy", but how did it also become a term to refer to a man's homosexual orientation? The term lesbian doesn't share the same dual definition...
"Gay" were used in France to say "perverted" and "lustful" but later it was used to indicate homosexual people. Do you know that in North Italy (in Piemonte, near to where I live), Gay/Gai is a very common surname? And there is also dialect called gai.
Originally meant care-free or joyful, then about 400 years ago morphed into meaning having loose morals, or being inhibited or immoral. About 150 years ago it was used to indicate promiscuity and prostitution. "Gay women" (prostitutes) worked in "gay houses" (brothels) which were frequented by "gay men" (punters/promiscuous men/womanizers). How it turned from a heterosexual adjective to a homosexual one in the last century is anyones guess. Perhaps people saw gay people as more hedonistic, immoral or sexually inhibited than their heterosexual counterparts so started applying "gay" to them?