Political abuse of psychiatry in Soviet Union has its own Wikipedia page.
Any ideas of how to fix it?
Make it contingent on prompt medical evaluation. The current timeframes for involuntary commitment in certain states can leave people confined on a Friday afternoon and waiting to be evaluated until Monday morning. If it's urgent enough for involuntary confinement it's urgent enough to have a medical professional oncall for prompt evaluation.
The medical necessity of all involuntary medical treatment should have to be substantiated in front of a judge, even if the patient is released before statutory deadlines would have required a judge to approve continued involuntary commitment. The medical facility should have to explain their actions e.g. "On Feb 12th at 5:12AM patient started scratching the skin off of their left arm (Exhibit A) which necessitated the administration of 10 mg of Midazolam intramuscularly". Any medication should also be limited to the shortest duration feasible until a court order is issued, no depot injections of Haldol that will last a month.
No financial liability for the patient. The state doesn't have to foot the bill for all of it, you could mandate that insurance picks up the tab and leave the state to pay for only the uninsured. It's profoundly unjust to not only deprive someone their bodily autonomy but also saddle them with a mountain of debt with no recourse even if the involuntary commitment turned out to be unjustified. If it came out of municipal budgets maybe police departments would be more diligent about making sure that involuntary commitment was necessary instead of using it like a blunt tool to pawn off a tiresome person onto someone else.