For instance, I give up the right to drive over 65 miles per hour on the highway in order to protect the safety of everyone else on or near that highway. It sucks that I can't drive as fast as I want to, and it's an affront to my liberty that's enforced with violence (cops will throw me in jail if I drive recklessly or persistently speed), but the government decided that that loss of liberty is less important than the damage to the general welfare if everyone can go as fast as they want (more car crashes and deaths).
Sometimes, the trade goes the other way. If we banned fast food, the general welfare would improve greatly. But the government (and ultimately the people who elected the government) decided that the resulting loss in liberty would be too great to justify.
In this instance, people lose liberty when they're restricted from holding certain professions[2] without licenses. But the general welfare is improved because now people can trust that their doctors and lawyers meet a certain level of quality[3] as determined by the state. The government weighed the lost liberty and the gained welfare, and made a judgment call. If we don't like that judgment call, we can vote for candidates who see things the other way (or donate to legislators who agree with your position, or start a grassroots organization and convince people).
[1] - There's also "establish Justice, insure domestic Tranquility, provide for the common defence", but those aren't in conflict in these examples. Government policy still regularly makes trade-offs between them. [2] - strictly speaking, you can own a law firm or doctor's office without a license, you just can't practice law/medicine. [3] - whether licensing tests are great reflections of ability or knowledge is beyond the scope of this comment.