Some of the housing regulations were legitimately put in place for safety reasons to protect people. Others were put in place to keep black and Asian people out. Especially after government initiatives to prevent discrimination in housing like the 1968 Fair Housing Act, efforts to keep out minorities became cloaked in the garb of "public safety", and minority-excluding regulations were sanitized into affordability-excluding regulations.
but it's a lot more than that. Blue cities are by far the worst offenders at anti-housing regulations. part of it must be that people are funadamentally extremely conservative when it comes to housing.