If a phone was on a pay monthly tariff companies will unlock the phone for the account holder/former account holder, usually for free. You just remain liable for your original contract to cover the subsidy on the phone
If on PAYG then they will be less keen, but are required to. A fee will apply because though payg is not as subsidised as contract phones there are some subsidies that companies give, still on the assumption the buyer will use it and top up
If you want to sell a phone then seriously consider unlocking to add value and make it easier for the buyer.
Note that once unlocked some phones will lock to the provider of the next sim inserted.