Section 13A. Upon a foreclosure of residential real property pursuant to chapter 244, a tenant, occupying a dwelling unit under an unexpired term for years or a lease for a definite term in effect at the time of the foreclosure by sale, shall be deemed a tenant at will. Foreclosure shall not affect the tenancy agreement of a tenant whose rental payment is subsidized under state or federal law and the foreclosing entity shall assume the lease and rental subsidy contract with the rental subsidy administrator.