This was a common slang term for gay men from the early 1700s to somewhere about 150 years after that. "Molly" was a purely descriptive, not particularly perjorative word, analogous to the modern "gay", and was the word gay men used to describe themselves. Really, at the time, this was about the only common word for the concept that there was-- "gay" and "homosexual" did not enter the language until much later. As far as i can tell, the idea of identifying gays as a distinct group deserving of a name was a fairly new one, and more often than not people even in this period seemed to refer to homosexuality as if it were an act rather than an inherent quality-- gays were referred to descriptively and usually in a roundabout manner, like "one who engages in that most horrible sin that shall not be named" as opposed to just "gay". The term "Molly" itself was some kind of reference to the feminine characteristics that mollies were assumed to be taking on.

See also buggery, Molly house. Or mollies, which is something completely different.