The story
- Middle English · inherited fromwerk
- English todaywerk
The LGBT slang usage is very recent and in essence an orthographical variant. It is independent from the far older and long-obsolete alternative form which derived directly from Middle English werk (noun) and werken, variant of worchen (verb).
Words from the same roots
Middle Englishwerk all →
wark
Etymology from Wiktionary, CC BY-SA 4.0.