Libertarians: this is why we have building codes. We don't need builders cutting corners and harming people years down the road, because profit convinced them that was the right thing to do for their own interests.
Just because some building codes have a good purpose doesn't mean all building codes do. On another forum there was recently a long discussion about the requirement for x number of power outlets in hallways of single family homes. This was added when wall-to-wall carpeting was fashionable and people in homes without outlets in the hallways were using extension cords so their vacuum cleaners could reach all of the car…
There is an opposite example to your hallway carpet example: many old bathrooms were not required to have outlets because there were not many mains powered bathing accessories, but now there have been multiple instances of people being electrocuted when running extension cords from other rooms into the bathroom to use.
Really, if we had outlets everywhere that met the best safety standards possible -- we'd prevent all of these issues, in any time. But we don't do this because people want to save money.