Carpo,
That's exactly the way a mortgage is supposed to work. Properly constructed mortgages are good deals that are designed to address violations by one side or the other.
If, on the other hand, you "violated the terms of your agreement" (for example, did not make your payments), and the agreement had NOT been properly structured to allow foreclosure by the bank, that would be an example of a BAD deal for the bank.
IOW, it's equally possible to be in violation of a GOOD deal as it is to be in violation of a BAD deal. The act of violating a deal does not mean the deal is good OR bad.

Best,

RTD