I don't know about anyone else, but I like the challenge of it. Writing my own stuff is entertaining enough, but in a world I create, I'm establishing all the rules, conventions, characters, and can do whatever I please with it. Writing for someone else's world presents a far more complicated challenge, because I'm dealing with a universe that already has an established story, with developed characters, and those characters have developed voices and personalities. The world has an established status quo of "the way things are."
When writing fanfic for an established universe, I have to keep all of that in mind. If I'm using established characters, I have to write with their voice (incidentally, my rule of thumb is usually if I can hear the VA speaking the line in my head, then it works, if I cannot, or if it sounds awkward, then I need to fix it). If I'm adding an original character, I have to develop that character all the while making sure that they feasibly fit within that universe in a way that feels like yes, this person could actually exist in this world.
And usually, when I'm doing fanfic, it's because I'm trying to address or take a closer look at something in lore that wasn't defined to my satisfaction. So I write fiction to work out the plot details that seem like they needed another logical step to fit together, or to look at a character that seemed like they really had more to say or look at. The one piece of fan fiction I posted here does a bit of all of those things - I took a look at a shaky period of Kirkwall's history through the eyes of someone who wasn't a hero at all, tied it back into Inquisition, and dug around in the Iron Bull's head while I was at it, because it felt like there was a lot more there that just hadn't been said, whether due to time and space constraints, or just because it hadn't been looked at yet. And on top of that I poked around with the logistics and reasoning behind the Qun, because I find it a fascinating concept for a fantasy setting.
If I do all of these things right, the piece should read like a logical extension of canon lore.
But that's me - and I'm pretty sure there are just as many different reasons out there for writing fanfic as there are writing in general.