Once upon a time, the word law stood for a system of rules that were very rigid and that the courts were obliged to enforce very rigidly. That system of rigidly enforced rigid rules often produced results that were harsh and intuitively unfair, and so there emerged a system of rules, practices, and the institutions, whose aim was to correct the harshness of the law, in that narrow sense, and produce the results that were closer to what seemed intuitively just. That system was called equity. (See the quotation in the WS2’s answer for a more formal statement of this.) In the terminology of the time, the law and equity thus stood in contrast to each other.
Over time, the two systems merged, and what most of us, in most contexts, nowadays call the law encompasses both the elements that have their origins in the law in that narrow sense, and the elements that have their origins in equity. There are, however, in the present-day law (in the broad sense) still numerous echos of the distinction between the law, in the old, narrow sense, and equity. In the context of legal practice, the word law continues to sometimes be used in the narrow sense, in which it is contrasted with equity.
What is crucial to understanding the shift that the question is about is that under the rules of the law, in that narrow sense, the mortgagee (the lender, e.g. a bank) holds the title to the property (i.e. is its owner), until the last penny of the debt is repaid; it is only then that the buyer becomes the owner. You could thus repay 99% of the debt, and still own nothing, in the eyes of the law, in the narrow, old sense. If the law, in that sense, controlled the outcomes, that would, of course, often produce harsh, unjust results. To prevent such injustices, the rules of equity emerged that treat the mortgagor as, in a way, owning something even before the debt is fully repaid. The word equity came to be used for what the mortgagor has, because his having it depended on the rules of equity.