Yes you can sell a home before you have the mortgage on the home paid off.
However when you do sell the home you'll need to pay the bank off with the proceeds of the sale of the home.
Then the new owner can take possession of the home once the bank has their money in full for the mortgage.
The buyers bank will pay off the bank to get the deed and then the buyers bank will keep the deed until the house is paid off by the new buyer.
You can then keep any proceeds of the sale of the home if there are any.
So before selling a home that is not paid off you should make sure your house has increased in value so that you will make more money than what the house originally was bought for.
If you still want to sell the home then you can also do so and get at least the money back that you paid towards the mortgage.
It's best to live in a home at least 5 years before you sell it so that it has time to increase in value and you can avoid capital gains.