Here’s the mentality. It’s actually quite easy to understand once you grok it.
People are too serious. They take themselves too seriously, they take the internet and their comments too seriously, they take their minute details of their lives too seriously. Being a troll allows you to counter this head on and to irritate the person or question the person for questioning’s sake (or for the lulz).
There’s also a certain level of fun gotten by irritating people like this. Think about trolling a Twilight forum, all these people fawning over this book series like it’s the best thing ever when it’s really just another book, clones of traditional story archetypes actually. And then it’s too easy, these people jump back and fight the troll with knives in their teeth and rage in their eyes, and that just makes it EVEN funnier to the troll!
Plus, it’s very easy to do this online. A troll likely would not be so rude face to face because that takes courage and justification (at least to avoid retaliation).
Why do they do it? I think the primary reason is lulz. They do it cause it’s amusing to them. There could be some components of insecurity/loneliness/social exclusion, but for the most part I don’t believe this is the primary driving force behind trolls. I think they do it cause they love to get a reaction out of others.