Building codes and inspections would prevent that more than licensing. If you want to make sure your house passes inspection the first time, maybe you choose to use a certified contractor. A government license doesn’t necessarily guarantee you anything. There are plenty of government licensed doctors getting sued for malpractice.
Good point, but in terms of government intervention in a marketplace I don’t think there’s a huge difference between a license requirement and a building code.