They identify with, and/or become attached to, the idea of the team, which as you point out, may not correspond well to reality or to logic. They feel like they are part of a community of fans, and invest emotional energy in it. They are invited to both by traditions of behavior, and by the language of sportscasters and other fans, and the language used by the team members, coaches, owners, etc. These people all agree to go along with this concept, even though it makes little sense. It does mirror human tribal behavior and other types of “us vs. them” behavior in many other ways.
It’s mostly not logical, but much of what humans do is more conditioned and inherited rather than logical. Most of what humans do is not because we think about everything and objectively conclude the behavior is logical.