All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Health insurance is a contract between the beneficiary and the insurance company through which healthcare is provided to the beneficiary and those covered under the insurance. Moreover, it is obligatory to adhere to the instructions that regulate the dispensing of medications to patients.
The fundamental principle is that medication is dispensed to the beneficiary only according to the doctor's prescription, and it is not permissible for the beneficiary to alter this prescription, even if they do not need the medication for recovery, for example.
If the medication is dispensed according to the terms of the insurance contract and according to the treating doctor's prescription, without any deception, and the existing illness requires the prescribed treatment, then there is no sin in disposing of the medication after receiving it, whether by selling, gifting, or exchanging. This is because the ownership of the medication transfers to the beneficiary after it is dispensed and owned in accordance with the terms of the insurance contract. And Allah the Almighty knows best.