The question uses investment-like terms, but really, you're just talking about selling your house.
So you'd probably use an estate agent to find a buyer, for which you typically pay a percentage of the sale price. The funds you receive from the sale would be used to pay off the rest of the mortgage, plus any other costs. Everything left after that is yours to keep.
If you're moving to another city, you might sell and buy at the same time, in which case, typically, the proceeds from your sale will be used as part of the deposit (down-payment) on the house you're buying.
If you're leaving the country, you could sell and keep any proceeds; or you could let the property to tenants (though you'd need either permission from your mortgage provider to do that, or to switch to a buy-to-let mortgage).
Note that buying a house for just two years may not be worth the trouble, given all the upfront costs (of which stamp duty is normally the biggest), the risk of the house's value going down in the short term - and the time (and stress!) that tends to accompany purchasing property.