I wonder when the phenomenon first started? Did the surviving young of the earliest human packs (or tribes or clans), listening to the tales their elders told around the communal campfire, then go off and create their own stories around the characters, putting themselves into the picture as the hero, or one of the others in the story? Or did it come later, with Hellenistic children self-inserting into the Iliad or the Odyssey? Or was it later still, as books became readily available and 'the novel' was established as a literary form in its own right?
Humans like to tell stories, maybe originally to explain a world they did not have the science to understand, or for entertainment. That tales grow with the telling goes without saying given the curious human need to embellish. Humans also, generally, like escapism (as shown by the plethora of entertainment of all kinds so easily available). Is this because we find real life so grim we need a way to escape it, even if just for a while? Or do we like the idea of ourselves in dramatic roles? Probably both, along with a host of other reasons. Some people will simply spin the fantasies in their heads, while others will write them down so they can be relived over and over again. As long as it doesn't get out of control it's harmless - often actually good, as a way of cheering ourselves up or relieving the stresses of living - and in the main very enjoyable.
But why do so many of us focus specifically on fanfiction? Because we aren't satisfied with how the original creators told the tales? Because we want to explore a favourite character or two in greater detail, devise a back story and further adventures for them? Because we want MORE? All of the above? (In my case, yes.) So we write fanfic.
Of course, the problem with that is it's now far too easy to expose your fiction to anyone who has a 'net connection - hence there are... things... out there that should have been drowned before birth and never allowed into the sweet light of day. To some writers spelling, punctuation and grammar are completely alien (so why should I read their work if they can't be bothered to learn the basics?). Some have absolutely no idea as to plot, or make the characters so appallingly out of character they're unrecognisable. No problem if the stories are just for your own consumption, or if you're part of a private writing group aimed at improving the writing of its members with constructive criticism, but to unleash them on the public? Embarrassing at best. Cruel at worst.
Let's consider one of my pet hates and one of the very basic mistakes writers (not just fanfic writers) make - the Mary Sue. Just about anyone who writes fanfic (and a lot who don't) will know about the Mary Sue (or the male counterpart, the Marty (or Gary) Stu). Originally written as a Star Trek parody, the character Mary Sue was the youngest person ever to graduate from Starfleet academy (at fifteen and a half). She was, essentially, perfect:
characterized by unprecedented skill in everything from art to zoology, including karate and arm-wrestling. This character can also be found burrowing her way into the good graces/heart/mind of one of the Big Three [Kirk, Spock, and McCoy], if not all three at once. She saves the day by her wit and ability, and, if we are lucky, has the good grace to die at the end, being grieved by the entire ship.
[quote from Menagerie magazine via wikipedia, because I'm taking the lazy option today. See more here.]
These days the term has come to mean an author's self-insert or proxy, a fanfictional form of wish-fulfilment, a poorly-developed character too idealised to be at all realistic. Though it should be noted such characters are not just in fanfic. A strong argument can be made that James Bond and Alex Rider are archetypal Marty Stus, and as for the best (or worst) Mary Sue I've ever found - well...
From outdrinking a member of one of the toughest alien species in the galaxy to taking on the smell and telepathic 'feel' of Spock's mother so she can comfort him, this woman can do anything. Shudderworthy. Don't you just want to slap her?
Yet at its best, fanfiction provides the fledgling (and experienced) author a way to hone their writing skills in a fictional 'safe environment' without having to be too original. It's a great way to learn how to delineate characters, how to structure dialogue, how to plot. And there are some truly excellent fanfic writers online who should be writing professionally: they are considerably better than some of the popular published authors around today (which may be why some authors refuse permission to have their works made the subject of fanfic, going so far as to take legal action if they find any. Jealousy - such an unflattering emotion...)
And writing fanfic is fun!
There are two main online sites I'm aware of, FanFicNet (a.k.a. the Pit of Voles: anyone can post here, and finding the good stuff amongst the dross can be time consuming) and AO3 (anyone can read here, but you cannot post unless you are a member, which requires an invite. In general the fiction here is of higher quality). Well worth a look.
[Obligatory self-laudment: my own current fanfiction project is The Poppy Tales. This is for general reading. There's a lot more fanfic, but it's all x-rated and behind a password at the main WaveWrights site.]