The short answer is that the mortgage is an asset and its value is the amount left to be paid on it, not the original amount of the loan. And if the transaction is for fair market value and a fair interest rate, there should be no transfer-of-asset issue if it is taken out within the five years before applying for Medicaid.
However, the reality could be more complicated, and potentially better. You might be able to argue that the mortgage should not be counted as an asset because there is no market for it. You can argue that it should be counted as an income stream with the monthly payments going to the facility. Of course, in that case it may still be in your estate at your death and subject to a reimbursement claim by the state Medicaid agency.
You might be able to use an irrevocable trust to get around some of these risks, but that would invoke the five-year waiting period. Since these strategies are treated differently in every state, we recommend that you consult with a local elder law attorney for a definitive answer. To find an attorney near you, go here: https://www.elderlawanswers.com/USA-elder-law-attorneys