You know how sometimes you hire a guy from a hemisphere you've never even heard of for a project, and when he delivers, it's nothing at all like you requested, riddled with bugs, and randomly crashes?
Now imagine that guy representing you at a murder trial.
Yes, licensing regulations also serve a useful purpose. But having the details of those regulations determined by the guilds themselves (rather than external authorities) is a lousy way to achieve that purpose. Why do I have to visit a dentist to have my teeth cleaned, rather than a dental hygenist? Why can't registered nurses or nurse practitioners provide basic medical care except under the auspices of a doctor? Because the rules are set by groups that represent the doctors and dentists.
It's also worth remembering that plenty of indigent people in this country are effectively represented by 'that guy,' including in murder trials. Look at the cases of Calvin Burdine or George McFarland, both of whose court-appointed attorneys slept through their trials. Are those barriers really doing what you want them to do?
That artificial barrier also happens to screen out a lot of unqualified people - which would be lowering the market clearing price otherwise. I posit that these barriers have no real effect on middle and top tier professionals in these fields.
The top computer programmers also make as much as top lawyers and doctors - possibly more if you count entrepreneurs.
It's not so much a price / cost issue as it is a respect issue. Can you imagine how the legal or medical profession would suffer if anyone off the street could claim to be a lawyer or doctor and get hired for the job?
Or to put it another way, to artificially erect barriers to entry that ensure they get paid more than they would in a freer market.