This chapter shall not prevent a mortgagee or person claiming under him from entering on the land or from recovering possession thereof before breach of condition of the mortgage, if there is no agreement to the contrary; but if the debt is afterward paid or the mortgage redeemed, the amount of the clear rents and profits from the time of the entry shall be accounted for and deducted from the amount due on the mortgage.
Mass. Gen. Laws ch. 244, § 9