Like how my father had stage four prostate cancer but he was actually killed by a side-effect of one of his medications.
They still count that as a cancer death.
Underlying cause of death in that case would be cancer. Immediate cause of death would be whatever issue was caused by the medication. The underlying and immediate causes are listed separately on the death certificate along with any conditions that complicated survival.
The UCOD is the disease or injury which initiates the chain of events leading directly to death. Patient develops prostate cancer -> given medication to treat prostate cancer -> dies from side effects.
I’m sorry for your loss. The reporting is normal and straightforward. It’s not there to mislead or “cook the books”. It’s there to provide a complete picture of what happened to each person who is deceased.