The number of Medical school admissions and future residency positions is pretty well controlled, so this kind of problem doesn't really arise (well, it's complicated but more or less).
On the other hand, any school can spin up a law program and start charging admission, no matter how qualified it is to actually do that. But it's only worthwhile going to law school if you can get into the first tier (Harvard, Yale, Columbia, NYU) or second tier schools. Third and fourth tier are basically a joke. You're throwing your money away. Of course, many people ignore that thinking they'll be different or lucky. And we end up with the kind of issues we see here today.
It's still more complicated, though, because a lot of what people from third and fourth tier schools used to do (sit in giant rooms and review case law for big cases), they are no longer needed for thanks to technology. So the 2000's onward was an awful time to want to be shove yourself through law school hail-mary hoping that just because you're a "lawyer" you'll be OK.
Law schools students got squeezed on both sides, and the pain is real. A profession that used to be much like medicine, where you would do "OK" in life at the very worst is now a commodity product thanks to forces from all sides.