There are a couple of things that religion does do well when it's done well.
Nowadays, there's a perception that religious thinking sits in diametric opposition to scientific progress, but this wasn't always the case. The calendar and our earliest models of cosmology got their starts by religious ritualists trying to predict weather patterns for greater accuracy - fuelled by the fact that the priesthood were really the only thing they had to what you might consider today to be a dedicated scholar class.
Add to that the inspiration of culture and the need in governance to organize an interface between regular people and local administration - somebody has to act as a listening post for people's grievances while also having the town mayor in their Rolodex, and for better or for worse the town priest is very efficient at filling that role.
Nonetheless, when religion is handled badly, everything you're saying is absolutely true.