There are lots of "drugs" that have been or are being used for medicinal purposes. Cocaine used to be used quite a bit. Marijuana is increasingly being used to treat certain conditions. I am not sure what they use heroin for but I would guess that it can be used to treat something. As long as a doctor is prescribing it for a serious condition there is nothing wrong with it.
No, pharmaceutical heroin is not a good idea, because it is extremely addictive. There are other products that physicians already use to manage pain for their patients. Patients would face too great of a risk of addiction and then use of illegal heroin after they were treated. There are simply too many risks for pharmaceutical heroin to be a viable option.