The mollies were a London subculture, noted for their effiminate dress and manners in the early 1700s. 'Molly' is a familiar form of 'Mary'.
Several slang words for gay men use a word that has a female reference. The most direct method is to use a female name. 'Molly' is the oldest known slang term, and uses this procedure.
Also 'Molly house' - an old 18th century term for a tavern or private room where homosexual and cross dressing men could meet.