I'm going to post an answer, and then I have to dig out the last time I answered a guild question on AskHistorians to recreate my bibliography. So, everyone bear with me. EDIT: I flat-ass can't find my previous comment. Perhaps the mods can help me--it was actually an Answer of the Week (or Month? or whatever) from a while ago, on the subject of construction trade guilds. I'd look up my sources again, but I'm far from my library.
I can provide an answer that's broadly useful for Continental Europe (primarily what is now Germany and France, Italy would be similar) in about 1500-1800 (wide time frame, but we're dealing with generalities here anyway), and addressed to construction trade guilds (carpenter, mason, plasterer, cabinetmaker).
There were two broad goals served by the construction trade guilds: controlling the quality of the final product rendered by the tradesman, and limiting competition.
As to the former, understand that the quality and the safety of a finished construction project in that time relied basically entirely on the work and supervision of the tradecraft. Other people simply had no basis on which to judge whether (e.g.) a masonry wall was thick enough to support a given load, a lumber joint was robust enough to withstand the forces on it, or a wall was well-made enough to last. Today, we have independent inspectors and owner-hired engineers and architects who understand construction well enough to independently verify these things. In that time and place, those folks simply did not exist. The master mason was the only person likely to know if a stone foundation was made thick enough, deep enough, of the right kind of stone, with the right kind of mortar, with the right mix of stone and mortar. And so society in general, the the tradecrafts themselves, needed some quality control. And that was done through guilds restricting who could practice, and requiring apprenticeships and certifications to practice the trade. In the absence of guild monitoring, the quality of the work could not be guaranteed (more or less), and failures would bring dispute on the trade as a whole. So it was in everyone's best interests to ensure that the people doing this work knew what they were doing.
The second, less purely civic-minded, goal was, simply, to restrict competition. If no one could be a mason without guild approval, and if being a mason required 5 years of apprenticeship, then the entry of new masons into the local community was predictable up to 5 years in advance. Further, guilds operated to restrict travel between various cities and provinces. In most guilds, only certain classes of workers had "transferable" licenses, and virtually all guilds reserved for their local "chapters" the right to refuse admittance to travelling workers--a trait that holds true for many construction labor unions to this very day. Restriction of the number of workers served to artificially restrict supply, which meant that for virtually any level of demand, the price would be higher than it would if supply was allowed to freely fluctuate.