The beneficiary shall not enforce or attempt to enforce an assignment of rents by demanding or collecting rent from a tenant occupying property consisting solely of a single-family residence, or a condominium, cooperative, or other dwelling unit in a multiplex or other building containing fewer than five residential units, without first giving the tenant either a court order authorizing payment of rent to the beneficiary or a written consent by the tenant's landlord to the payment. It is a defense to an eviction based on nonpayment of rent that the tenant paid the rent due to the beneficiary pursuant to a court order or a landlord's written consent.