What Karl Marx is saying here is that religion is like a drug. Specifically, it is like a drug that keeps people happy so that they do not want to rebel against the oppressive governments and societies that hold them down.
Marx believed that all people in the oppressed classes would inevitably rebel against those who held power in their society. Peasants would do this to feudal lords, workers would do this to the bourgeoisie. But this often did not happen and workers, for example, often showed no desire to rebel. Marx had to explain this.
One way in which Marx explained this was to say that religion helped to keep the people down. They would focus on the lives of their souls instead of material things. They would disregard their problems on earth and focus on the idea that they would be rewarded in the next life. In this way, religion kept them from wanting to rebel. It kept them focused on something other than the way they were being oppressed.
This is why religion was, for Marx, the opium of the masses.