I'm just going by common sense, but if you are part of a group, you are a representative of the group (and vice versa).
Therefore, if there is fault with the group, it is as if you had a fault as well, and you try to defend yourself against that indirect attack.
That's how I see nationalism and scapegoating behavior.
As for teams and fanboy wars? To me, that's more like just fun and not the same as nationalism or those kinds of groups... But I guess it could be similar. If I bought the console, and if my console is bad, then I made a bad purchase. And if another console is bad, then at least mine has to be better (or good, if there's only 2-3 consoles in the market).
It's kind of a circle jerk I guess. Praising yourself, and defending yourself via group.
I find it ridiculous that people take pride from being in a group.
People will point to the famous leaders, artists, inventors of their group, say the group's name, and act like I they contributed to those individuals' achievements.
People will point out a feature of their console, and act as if they had some magnificent feature as well.
Why people scapegoat, and why outcasts occur in groups is that if they do not kick these people out of the group, those outcast's attributes and qualities are applied to them as well. It's been like that since ancient times and now.
So this is just simply a basic pattern. Be a part of the group, and you get to share in all of its glories and achievements, whether or not you did it or not. You defend the group, and you praise the group, and in doing so, you defend and praise yourself.