When Marx wrote that “religion is the opium of the masses”, he did not necessarily mean to disparage religious systems, as is popularly interpreted. Popular interpretation of that system is correct in that Marx is refuting or denying that any religious system is true. Popular interpretation is also correct in believing that this statement is regarding the rôle of religious systems. But popular interpretation is wrong in believing that this statement is inherently anti-religion.
Back when Marx wrote this, opium was used as a medicine, as a pain-reliever. And so what Marx meant was that people turn to and cling to religious systems because it soothes their pain or even dulls it. Indeed, one might express the same sentiment today by staying that religion is the morphine, Vicodin, or Tylenol of the masses.
That said, in later explanations and extrapolations of his theories, Marx placed religious systems squarely within the hands of the oppressive classes. The oppressive classes exploited the people’s tendency to turn to religion, exploiting it by using religious systems to enhance their hold on and control of the masses. This is seen as somewhat ironic considering that the oppressive classes established the conditions of misery and pain because of which the people turned to religious systems for solace, comfort, and relief.