"Literature is a luxury, fiction is a necessity", said G.K. Chesterton. We all need that escape out of the real world (which may not be as real as it pretends to be) into story. In story the rules are simpler, there's authorial control, less randomness, fewer boring bits and we can engage our emotions without ever getting really hurt. In Chesterton's day they had books and theatre. These days we also have cinema, TV, radio, RPGs, video-games and the internet. It feels good to get lost in story. The danger is we get in too deep and stop paying attention to the real world.
Like Don Quixote.
So that's one reason for fandom. It's about getting deep into story and exploring it beyond the bounds of canon. Fanfic turns finite story into never-ending story.
The other reason for fandom is the human need for community. Fandom functions like any other community- like a church, tribe, clan, gang, order, fraternity, sorority, club, whatever. It's about people bonding round a totem. Only the totem here is not a deity or a secret or an oath or shared blood, but a work of fiction. Compared with other types of community, fandom seems relatively benign. Some fans despise outsiders (as some wizards despise muggles) and there's always the temptation to turn inwards and separate from the herd on the model of the saved and the unsaved, the sheep and the goats, but, on the other hand, there doesn't seem to be much in the way of hierarchy, membership is open to anyone who cares about the totem, and the values implicit in the totem (LOTR, Trek, Star Wars, Potter are all highly moral works) are likely to keep most members on the straight and narrow.
There are some extremists. I still think that picture is a bit iffy. But has fandom committed any murders, rapes, persecutions, terrorist outrages, invasions of a foreign country? Not that I'm aware of.