Jobs in medical specialties *are* effectively union-protected. The unions are the boards that define the residency quotas.
Opthalmologists should make a good income. But their income is paid by the rest of us, directly or indirectly. There is no good reason why we should pay them four times what we pay (for example) a pediatrician or ten times what we pay a veterinarian.
Many more people have or had the ability to be an opthalmic surgeon than to be a Nobel prize winner. But our society pays the opthalmic surgeon many times more. I’m not actually personally upset about this. Hey, maybe my spouse is a surgeon–you don’t know. I just think it is irrational and inefficient, and the more other people know about this, the more likely it is to change eventually.