It is well known in evolutionary theory that the question whether some trait X is a byproduct or an adaptation is not fixed once for all. The same applies to cultural entities or traits.
One thing we can say with some confidence is that if religion did started as a byproduct, this does not mean that it stayed that way. Indeed, if it had no function or even a slight negative function, it would be unlikely to persist for long. Well known in evolutionary biology is the move to a positive function for which a feature was not originally designed—what have been called exaptations
Whatever the function or not of religion as it began, it could be picked up quickly by natural selection and turned to other uses. And if Durkheim and the other social scientists who think his way are even half right, the use is obviously some kind of group cohesion, where people benefit from being part of a society and not individuals alone.
But it would be false to claim or assume that something that has been useful - an evolved adaptation - has to stay that way forever. Something can start as a byproduct, then become an adaptation and later turn out to be useless or even detrimental after the environment has changed.
As for religions, the case is far more complicated than many of those who have written about it have argued. My impression is that there is some good evidence that religious beliefs and practices started as a byproduct of human cognition and emotional needs, but then became an adaptation or exaptation (otherwise it would be difficult to account for (a.) the long and intensive symbiosis between religious ideas and human societies, and (b.) the rich cultural evolution of religions, from simple beliefs about ancestors and spirits to complicated doctrinal systems like Roman Catholicism).
The situation today is fairly complicated, depending on three different aspects:
The answer to the question "Is religion useful, useless or detrimental?" depends on the answers to these three questions. Everything else is simplistic and should not be taken seriously.
When religion is concerned, one-size-fits-all answers simply do not work.
This debate addresses the question. Worth the watch.
I think your question assumes that there is one single entity that the usefulness of "religions" can be measured. Useful to whom and detrimental to whom? The religion is a self-replicating set of ideas, and if it is good at self-replicating, and if it benefits the powerful sectors of its hosts, it doesn't necessarily mean that it is "beneficial" to everyone in general.
If you look at pre-jesus hebrew religion, the religious elites maintained power, using the religions as a reason why they should wield the power. If the religion benefits the ruling class to persist in their rules, and the ruling class as a result of the religion continue to florish, is it beneficial or detrimental? Is it useful or useless?
Is there an easy answer to the old question "Is religion useful, useless or detrimental?
The answer is easy. It is yes.
Even placebo effect has its uses, and religion is 100% placebo effect.
I can see how it provides hope in seemingly hopeless situations. I can see how it provides a sense of ultimate justice in a universe that has none. I can see the sense of community that's sadly lacking in the atheist/agnostic/humanist world (something this very website is making a good effort to address online, but which needs sorting in real life, too.)
All of the above... like many other things in life under human administration.