(Note that this focusses on a rule on the number of legally-unrelated people that can legally live in a unit, but it also mentions in passing a separate restriction on the total number of people who can live in a unit irrespective of family relationships.)
Sharing a house with too many people is illegal in many jurisdictions, yes. E.g., https://www.sfexaminer.com/news/urban-development/sf-housing...
(Note that this focusses on a rule on the number of legally-unrelated people that can legally live in a unit, but it also mentions in passing a separate restriction on the total number of people who can live in a unit irrespective of family relationships.)