If a tax on land is assessed to a mortgagor and mortgagee separately, any part thereof remaining unpaid on October first following its assessment may be paid by either party. If a mortgagee pays a tax, interest or costs thereon which by law or by the terms of the mortgage was payable by the mortgagor, the amount so paid shall be added to the mortgage debt. If it is by law or by the terms of the mortgage payable by the mortgagee, and is paid by the mortgagor, the amount so paid shall be deducted from the mortgage debt unless the parties have, in writing, otherwise agreed.
Mass. Gen. Laws ch. 60, § 59