It's a double-edged sword, in that religion fosters a sense of community and belonging, but only to the specific group. In areas where one religion or denomination dominates, the sense of community and social support is very strong... unless you don't belong to the dominant group.
This isn't all that different from the way humans form social bonds and build communities, with the exception that religion tends to set the stakes very high, not only life or death but your eternal future is at risk. And that can make those social bonds detrimental and potentially dangerous.