State or city law or ordinance, who knows? Some local laws limit the number of people who can live in your house. I’m not sure I see the legitimacy in such a law.
Those ordinances probably came at a time when certain culture enriching activities were viewed as things that would lower property values and be annoying to live near; ie grandma& grandpa , aunts & uncles, mom &dad, kids and cousins all living like sardines in one house.
Just a guess, but cities used to pass ordinances to protect property values.
When I lived in Manassas, Virginia, we had a problem with groups of illegals inhabiting 3RR townhouses: we were talking 20-25 (with kids) in a 1800 square foot TH. . .
After one nearly burned down a TH in my development, the local County government passed a law limiting a house to no more than 5 unrelated inhabitants. . .
Towns near colleges often restrict occupancy of unrelated people.