First, to clarify some terminology. The issue in this situation is whether there is any civil legal liability. When someone asks whether something is legal or illegal, that is usually referencing criminal activity that can result in charges in criminal court. For most medical situations, the issue is whether the care was provided according to standard medical care, regulation, and medical ethics, and a failure to do so may result in being liable in civil court or for disciplinary action being taken by the licensing board.
Although regulations will vary somewhat from one state to another, it is usually defined in regulation that a proper discharge from the practice involves providing proper notice, facilitating transfer of care to another physician, and providing appropriate urgent medical care for the period of time stated in the notice. Most states define that period to be 30 days. The issue becomes the interpretation of what constitutes proper notice and appropriate medical care. Verbal notification may be sufficient notice. The real issue in these situations, though, is whether the doctor can refuse to prescribe pain medicines in such situations.
In situations in which the doctor judges that the patient has not followed the proper process, such as obtaining controlled substances from another doctor, taking the medicine different than prescribed, or diverting drugs, it is considered standard medical care for the doctor to refuse to provide further controlled substances, even if the patient is not discharged from the practice. The doctor may say that the patient can stay in the practice and he will treat the patient with every available treatment other than controlled substances. It is also not considered a violation of medical ethics. In such situations, if the patient is discharged from the practice and the doctor does not refill the controlled substances, that is still compliant with the process for terminating the relationship, because the doctor has decided on appropriate care, whether the patient stays in the practice or not.
As with many issues that are dependent upon physician judgment, there may be different decisions from different doctors, but if the doctor has valid clinical justification for the decision, medical boards have consistently determined that the doctor acted appropriately.
So, the decision to not provide controlled substances when the doctor judges that the patient did not follow the proper process is not a violation of regulation, standard medical care, or medical ethics.