Exactly. It's just that the trait doesn't have to be useful. It just has to be not harmful enough to skew the balance.
If the net balance between use and harm of whatever constellation of traits causes religious behaviour is good enough, it'll stick, even if the religious behaviour it causes CAN cause problems.
If evolution lacks one thing, that's foresight. Religious behaviour may have even been of some kind of use at the point it came to be, but that doesn't mean it still is. Going by memetics even, it just needs to survive in a host long enough to infect another to ensure its survival.
If the net balance between use and harm of whatever constellation of traits causes religious behaviour is good enough, it'll stick, even if the religious behaviour it causes CAN cause problems.
If evolution lacks one thing, that's foresight. Religious behaviour may have even been of some kind of use at the point it came to be, but that doesn't mean it still is. Going by memetics even, it just needs to survive in a host long enough to infect another to ensure its survival.