Marx didn't really advocate state anything. He was firmly of the opinion that the demise of religion was essential to the foundation of a truly egalitarian economic system - as religion was primarily a tool used by the ruling class to control the people - but he never advocated that it be forcibly suppressed. That was a Leninist development.
One thing that is essential to understanding Marxism is that it's dialectical. For every effect, there is an equally valid counter-effect. Capitalism is the source of inequality, but equally the inequality of the system will eventually destroy it. Similarly, religion is an instrument of control, but its very existence is an effect of the people's dissatisfaction with the system. Once people figured that out, he believed, the more egalitarian atheist belief would emerge as a presage to socialism.