This may be the best book to read on the topic: Breaking the Spell by the philosopher Daniel C. Dennett. In short: religion is a meme (that has evolved over centuries). Crudely put, one can draw some parallels between religion "infecting" a human and a virus that makes an ant crawl to the top of a blade of grass (as the virus needs a sheep's stomach to reproduce).
https://www.amazon.com/Breaking-Spell-Religion-Natural-Pheno...