If we assume that the reason patients get finasteride this way is to get insurance to cover it, and the doctor has no evidence to suggest the patient actually has an enlarged prostate, and further doesn't document a physical exam confirming the enlarged prostate, it's basically insurance fraud.
If this is simply a way to get the patient pills via prescription regardless of the insurance coverage (you said yourself that it's cheap, and hair loss is cosmetic and therefore shouldn't even be covered by insurance), this is even more stupid, because doctors are well within their rights to prescribe or administer medications that are FDA approved for one condition "off label".
In this case it was done just to save the doctor the hassle of arguing with the higher ups. It's been a while, but if I recall correctly, Merck was aggressively enforcing its patent rights. It was even raiding compounding pharmacies that sold lower dose formulations of finasteride instead of the brand name Propecia.
https://news.walla.co.il/item/932056 (Google Translate does an almost reasonable job)
""" Note: Be cautious about using data that was primarily created for insurance purposes. Often, it's not truly reflective of patient's condition but rather encompassing for billing / profit. Luckily, there are clinical reports, like radiology, diagnostic imaging, pathology reports, etc., that are intended for physician use and are more reflective of true patient conditions. Unfortunately, most of this data is not readily available in APIs because it's largely unstructured. This is a ripe space for ML to take raw, unstructured data and produce structured, computable data. """
Large practices have treatment standards on which physicians are evaluated. Reporting side-effects might be politically inconvenient in some cases. Medicine is also, like other human endeavors, subject to fashions and fads.
At best, applying machine learning to health records will generate a hypothesis that must be checked in a properly controlled trial.
I work with insurance claims and post-marketing adverse event reporting data for pharma drugs, and I don't recall seeing anything resembling what OP described when looking at offlabel usage, but it's been awhile. (note: this is not EHR data, but it relates)
Anecdotally I've had a few off label RX's that weren't attached to any DX code in my EHR, same with my wife.
* edit: said 'you' vs. OP
Wow!!! Great observation.
One thing though, if ML/AI can detect when they are political-economic vs when they are medical then maybe you could apply some of the techniques of ML/AI
Here is a simple example why:
Finasteride is a compound that is used in two drugs. Proscar is used for prostate enlargement. It is old, out-of-patent, and has cheap generics. Propecia is used for hair loss. It is a newer, and (at the time) very expensive. The only difference is that Propecia is a lower-dose formulation.
What people did was to ask their doctors to perscribe generic Proscar, and then break the pills up to take for hair loss. Doctors would then justify the prescription by "diagnosing" enlarged prostate. This would enter the patient's health records.
If you apply deep learning without being aware of this "trick", you would learn that a lot of young men have enlarged prostates, and that Proscar is an effective, well-tolerated treatment for it.
Health records are often political-economic documents rather than medical.