There are three main reasons to write fanfiction or "fanfic," which is the amateur use of existing characters or settings by someone other than their creator. (For example, if I write a story using the characters from H.G. Wells' The Time Machine, I am writing fanfiction, because I am not H.G. Wells and the characters don't belong to me.)
1. Dissatisfaction with the events/ending in canon
I did this with the ending of Allegiant by Veronica Roth. The ending in the book tore me up so much I couldn't stand it, so I wrote an alternate ending.
2. A desire to see the characters in a specific relationship
This reason represents a huge percentage of the fanfiction community, and often what makes those outside "the fandom" uncomfortable. Not all of it has to do with sex, but a lot of it does.
3. Curiosity about how the characters would interact with a different setting, situation, or set of characters
Curiosity and exploration are, I think, the ultimate reasons behind any kind of writing, whether the author realizes it or not. In fanfiction, it might show up as "what would happen if Ginger from Black Beauty survived and was rescued at the end?" or "how would Harry Potter act if he accidentally aparated onto the U.S.S. Enterprise?"
These are relatively innocent reasons to write, and might be applied to anything I put down in words. So why are there so many people that seem to think that fanfiction is a bad thing, or simply worthless?
One might think it's Bad because of reason #2 above, which leads many young writers to pen anything from innocent flirting to what amounts to soft porn. That makes a lot of folk in authority positions over young people very uncomfortable, and for good reasons. CNN released an article (linked here) in July of 2017 concerning this aspect of fanfic, and I would recommend reading it for more information.
Others might believe that fanfiction is worthless because it can't be published. No work utilizing copyrighted material can be published as original. So, when a writer creates fanfiction, there's no way they'll be able to make money off of it without direct permission from the person or company that holds the copyright to that material.
Personally, I think this second is only an issue if making money is your primary goal in writing.
In sum - yes, there can be some problems with writing fanfiction and the fandom as a whole. But I think you'll find that this is true of any community made up of flawed human beings, and any action taken to an extreme or used for twisted purposes.
Fanfiction is not inherently bad. We need only keep an eye on it to make sure it doesn't run away with us. :)
If you have any questions, comments, or suggestions, feel free to let me know! Feedback is LIFE.
Until next time, stay awesome, readers.