A few years ago, information for tenants in buildings facing foreclosure was hard to come by and somewhat contradictory. Now, though, there are some new laws and a great deal of clarification.
MGL c.186, s.13A, added in 2007 states: "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."
PL 111-22, a federal law added in 2009, is called the Protecting Tenants at Foreclosure Act, and applies to 1) buildings with federally-related mortgages, 2) any dwelling or residential property or 3) Section 8 tenancies. A tenant with a valid lease can stay until the end of the lease period, and 90 days' notice must be provided to tenants without leases. There are different protections for Section 8 tenants.
There are also several good web sources with analysis of the laws. The Attorney General's Information for Tenants in Foreclosed Buildings provides straightforward information and links to other sources. Mass. Legal Help's Tenants Facing Foreclosure goes even further, and provides helpful advice on getting your security deposit back. Security deposits can be tricky, because MGL c.185, s.15B(7A) specifically states that security deposit protections do not apply "to a foreclosing mortgagee or a mortgagee in possession which is a financial institution chartered by the commonwealth or by the United States".
More information on tenants in foreclosure situations is available at our Law About Foreclosure and Law About Eviction pages.