Most of that stuff is written by girls. I think it's a fairly universal thing and didn't arise in any one place. e.g. I can count at least three origins for that sort of thing
there were gay romance novels written by women at least from the 1970s, as well as 1970s Trekkie slashfic spread in fanzines, and 1970s Japanese BL manga. All of which was well before the internet so they probably never heard of each other's work. If the same thing arises multiple times in different cultures but ends up being pretty similar (e.g. BL doujinshi stuff is pretty similar to slashfic stuff) then there's probably something deeper to it.
I think it's an evolutionary thing, there's a few animals which exhibit what I can best describe as a fetish for homosexual behaviour, either males being attracted to two females having intercourse which I recall reading about in goats, or females being attracted to two males having intercourse as in ruffs.
Makes sense to me that humans would exhibit similar behaviours occasionally.
I'm not sure what survival advantage that gives over not having that, any ideas?
And now, a rant about fanfiction shipping
People seriously need to stop, why would you ship these two characters who A. have sexualities in canon that don't work, the first one thinks the second is a horrible monster, correctly I might add, and the second tried to KILL not just the first, but all the firsts friends and family, AND the firsts entire way of life, to take their land, and the second probably never heard of the first, and the second is A. Insane B. Probably incapable of love, and C. may or may not have been neutered (yes, these are cats) seriously guys PLEASE STOP
The same reason any fan-fiction gets written.
"WISH FULFILLMENT"
There are some (very few in my experience) creators of fan fiction that take great care to answer a "what if?" question, within the scope of established character development, plot narrative structure, and setting provided by the cannon material, to actually answer that question as best they are able to do.
Then, there is the steaming heap of basically all other fanfic, which basically amounts to "Yeah, but I like THIS better!", into which all kinds of horrible things gets piled.
I rather dislike this second, very large demographic. It basically takes the work of the original creator and smears feces on it, then says "SeE! MyNes BEtT3R!"
Want to make the male protagonist into a female for no justifiable reason other than because you want to? SURE--- In fact, make her a gritty lesbian that likes red flannel while you are at it-- Oh, and have her eat babies alive too. (because literally *ANYTHING* goes in this pile, because by deciding to discard the reality presented in the cannon, you have decided that those kinds of rules dont apply anyway. Go a head, write your own story, ---with BLACKJACK, and HOOKERS!)