These are challenges for people sharing housing, but they're not the legal reason why letting out rooms is illegal. Prohibitions on multifamily housing are all rooted in racial animus. It's the entire reason we have single-family zoning (a related legal proscription), which emerged very shortly after the Buchanan v Warley decision that outlawed outright racial zoning. There's a long and well-documented history of this, all the way down to regulations targeting multi-generational households (Black and Latino families are more likely to have a grandparent or aunt living alongside a younger family).
"The Color of Law" is a good starter read here.