This is the section behind the phrase "the roommate law", and its arithmetic is precise. A lease signed by one tenant is construed to permit occupancy by that tenant, the tenant's immediate family, one additional occupant, and that occupant's dependent children - provided the tenant or the tenant's spouse occupies the apartment as a primary residence. A lease signed by two or more tenants permits occupancy by the tenants, their immediate family, occupants and occupants' dependent children, so long as the total number of tenants and occupants (not counting the occupants' dependent children) does not exceed the number of tenants named in the lease, and at least one tenant or a tenant's spouse lives there as a primary residence.
Subdivision 2 makes the point that gives the section its force: it is unlawful for a landlord to restrict occupancy to the tenant or to the tenant and immediate family, whether by express lease terms "or otherwise", and any such restriction is unenforceable as against public policy - in leases signed before the section as well as after. So the clause in the lease saying the apartment is for the named tenant only does not do what it says.
The section also imposes duties on the tenant and preserves limits for the landlord. The tenant must tell the landlord the name of any occupant within thirty days of the occupancy starting, or within thirty days of the landlord asking. Subdivision 6 is the one occupants misread: without the landlord's express written permission, an occupant and the occupant's dependent child acquire no right to continued occupancy if the tenant leaves, and no other rights of tenancy. Subdivision 8 preserves the landlord's right to restrict occupancy to comply with federal, state or local law - the occupancy standards in building and housing codes are untouched. Subdivision 9 gives an aggrieved person an action for an injunction, actual damages and court costs.