Historically, women frequently died from child birth. Modern medicine has made child birth significantly safer for both mother and child. These advancements need to be disseminated to individuals, and society has a need to determine whether or not a person knows the latest scientifically sound techniques.
Professional licensing fulfills this role.
Of course, it's more expensive to hire a person whose spent years training. But without some verification, there's going to be a race to the bottom as untrained individuals undercut the competition. And yes, it does act as a barrier to entry for people who could do a great job.
But, the risks of hiring an poorly trained midwife are much more serious than those of hiring an untrained software developer. Thus, society is okay with having unlicensed people writing software but isn't okay with unlicensed people treating them for injuries.