Being in the construction industry myself and having to learn the building code here in Ontario, I've often had the same conflict in my thoughts and with others. For the most part, the building code here is what I think it would be if written by a private organization, in that construction professionals ranging from designers to builders to safety specialists (among others) are consulted to craft the Code.
Still, the fact that government is involved and assumes every builder will construct a tinder box that locks from the outside during a fire is pretty ludicrous. Owners, insurers, bonders, banks, lawyers, subcontractors and every other project participant would be involved in taking an unsafe builder to the cleaners at court. And in my company, health and safety comes above everything, which is one of the bigger reasons it's doing so well. People and other companies don't want to do business with unsafe builders, and news of any major accident resulting in serious harm or death gets around quick and can really damage a clean reputation. And actually, even one major safety incident, or a few minor ones on record, can mean the difference between getting a job or not, even if you have the better bid (same goes for pre-qualification on big projects).
I do think that government involvement in building codes (or any safety codes) is immoral, but it's kind of like the argument with roads: government shouldn't be involved, but as long as it is, it may as well set the safety standards to a reasonable level. If I get a chance I'd like to try to reverse that, but I'd be one drop of water going against the current.