Pinpointing the exact origin of "gay for it" is tricky. Like most internet slang, it bubbled up from forums, social media, and meme culture. One early and influential use came from the video game and anime community. A popular meme format, often featuring a character like Solid Snake from Metal Gear Solid or a handsome anime figure, would be captioned with something like, "I'm not gay, but I'd be gay for him."
This format exploded on sites like 4chan, Reddit, and Tumblr in the early 2010s. It was a way for straight men, in particular, to acknowledge male attractiveness without fully abandoning their straight identity. The humor came from the contradiction. It was self-aware. It was ironic. And it was surprisingly honest.
From there, the phrase bled into mainstream culture. Comedians used it. TV shows referenced it. It became a shorthand for a very specific kind of attraction that didn't fit neatly into the gay/straight binary.