Well, heroin was synthesized to be a stronger painkiller than morphine, but with less of certain side effects - meaning a smaller dose would be sufficient for a particular pain, and the patient’s breathing would be less depressed (depressed breathing puts you at risk for things like pneumonia and, if extreme, death). The attempt was successful, but the downside was heroin was even more addictive than morphine. Heroin is used medicinally on a limited basis in Europe, but not in the United States.
Methadone was synthesized by the Germans in WWII (if I recall correctly - may have been as early as WWI) because their source of natural opium had been cut off and they still had lots of war-wounded in pain. It was also designed to be a long-acting painkiller. For instance, a dose of morphine or heroin typically last 4-6 hours. A dose of methadone lasts 24-72 hours. Methadone is used to treat opiate addiction (with some controversy) and also to treat pain, such as with cancer patients. It’s long acting properties reduce the number of pills/shots per day in patients who are already consuming vast quantities of pharmaceuticals, and because it is long-acting, avoids some of the swings in state of conciousness of the shorter-acting natural opiates.
That’s two examples - I’m sure there are other reasons for other synthetic forms of opiates.