Marx had to write lot. Writers write and some of the rich, maybe the vulgar ones, try to prevent that. Philosophical writers ask questions about social justice and scribble thousands of words about it; discomforting the upper classes.
Plainly Marx and socialists maladroitly sought to oppose Christian faith in their efforts toward political revolution. Europeans had a lot of church/state wealth leadership packed together. Churches owned a lot of land before the Protestant insurrection against catholicism's monopoly upon legal meetings of faith. The socialist revolutionaries were idiots in that onerous divide and conquers agenda though. God is actually amused by the follies of mankind at all levels. The socialists could make no subtle religious distinctions on faith or biblical content being ham fisted.
God isn't mankind whom slog about in the morass of original sin that is reinforced and contained in thermodynamics. Jesus was what God was like when he became man. What rich person or government does what the Lord said to do? Socialists may as well have been in the mob demanding crucifixion of the Son of God. Idiots.
Marx may have known that opium was a trendy dope of the rich and that the poor couldn't afford it. The poor, who are blessed from a certain perspective in that they have a better chance than the rich to enter the kingdom of God. The rich cannot just buy their way to heaven. The poor did have the consolation of faith in God. Some people have notable happiness and positive brain chemistry changes in prayer.
Marx was influenced by the notable atheist Feuerbach and also may have had an intellectual elitist's contempt for the masses lacking 'class consciousness'. That is they weren't 'woke' and didn't know that various socialists believed the masses should have an insurrection against the rich and royalty at least to be respectable of they incapable of honest revolution.
As a sophisticated career librarian Marx had all of the books he could ever want after his philosophy career ended. Marx was a great economist and social analyst obviously, yet really less on the gospel of salvation and that it promoted equal rights and even democracy. Jesus had high regard for the poor.