Praise be to Allah.
With regard to identifying what medicine the patient needs and how much, reference should be made to the doctor who is treating him, not to the pharmacist.
Based on that, there is nothing wrong with the pharmacist dispensing medicine covered by medical insurance to the patient, even if he thinks it most likely that it is more than he needs. In that case, the sin is on him [the patient] and on the doctor who prescribed the medicine for him, if he prescribed something that the patient does not need, because of what that involves of lying and consuming the insurance money unlawfully.
The pharmacist does not have the right to dispense anything to the patient except what has been prescribed for him, such as if he wants to exchange some of the medicine for other things, such as cleansing materials or cosmetics, because he is entrusted to dispense what is in the doctor’s prescription, and because of what that involves of lying to the insurance company by recording medicine that the patient did not receive; rather he received something else.
If the patient takes the medicine that the doctor has prescribed for him and that he actually needs, then it becomes his property and it is permissible for him to give it to someone else, on condition that that will not lead to him asking for more than he needs.
But if he takes it by way of trickery or lying, then it is unlawful wealth that does not become his property, and it comes under the same ruling as wealth that is seized by force or stolen; he must return it to the insurance company, or return a substitute or its value, because the Prophet (blessings and peace of Allah be upon him) said: “The hand that takes is responsible until it pays it back.” Narrated by Ahmad (20098), Abu Dawood (3561), at-Tirmidhi (1266) and Ibn Maajah (2400). Shu‘ayb al-Arna’oot said in Tahqeeq al-Musnad: It is hasan because of corroborating evidence.
And Allah knows best.