Religion might be the excuse, but the reason is political power, and builds on basic tribalism.
The danger is that by reacting with more violence, it pushes more disaffected people into the arms of the radicalisers, which in effect 'rewards' those who plan these attacks.