The mortgage can be changed only with the consent of the mortgage holder. For instance if two people divorce, one may give up all interest in the marital home, but this DOES NOT relieve them of the liabilities of the mortgage. That has to be taken up with the bank/mortgage company and will depend on the remaining person's credit history/score, etc.
In addition to what Mr. Carini indicated above, the one wanting to keep the mortgage can re-finance in only his/her name if qualified. Of course, the deed should be transferred to the person keeping the property before or during the re-finance.