The payoff of the mortgage does not go into the calculation of gain or loss in terms of taxable income.
Selling price
minus
Expenses of sale (repairs, closing costs, etc.)
minus
Your basis (Purchase price + costs + improvements)
This calculation is how you determine gain/loss on sale. The mortgage amount does not matter.