Hi. Anthro here.
Formalized religion is relatively new. It developed around the same time as inequity/specialization. Before, shamanism was the standard belief system.
Also, I believe Marx meant that religion was the pain relief for the masses. It’s been misinterpreted.