I'm watching Gomorrah, a very gritty TV series about the Italian Mafia. These guys have some similarities (minus the religiously motivated violence). Selling heroin to kids on the one hand and being super religious on the other. It's more tribal identity than moral philosophy.
It's more about mentally unhinged individuals who have lived a violent, unsatisfying and anxious life finding something that resembles meaning, discipline and, perhaps most importantly, redemption in religion.
Not only shall all their sins be forgiven if they renounce wicked immoral ways, they shall also be rewarded in the afterlife for all eternity if they enact god's will.
It's not hard to see why so many find that more appealing than just trudging ahead with what they realize is a pointless, meaningless and often short life.