You can sell your house at anytime you want too while having a mortgage but it's not recommended to since if you immediately sell your house a few months or so after buying the home you won't have built up enough equity or allowed the house to increase in value to profit from the home sale.
It's recommended that you live in or keep your house for at least 5 years before you sell the house you've gotten a mortgage on to allow enough equity to build up in the house to be able to profit from the sale.
When you do sell your home with a mortgage you'll need to pay the mortgage off in full and won't be able to make payments on the mortgage.
They'll also be taxes that you need to pay from the proceeds of the sale. So it's recommended to wait at least 5 years before selling a home you have a mortgage on.
During that time you could move to a new home and take out another mortgage and then rent your current home out to someone else that can cover your mortgage and give you a profit.
If possible you could even just keep that current house as a rental property and continue to cover the mortgage plus profit from the rent if you're interested in being a landlord.