If a person (friend of mine) holds a Tier 2 UK visa (actually, a spouse variant of Tier 2) and their passport is expiring within a couple of month - can that person still exit and enter the UK freely before obtaining their replacement passport? The person can't enter the UK visa-free, if that matters. The gov.uk website doesn't give any info on that, or I'm really bad at searching it properly. I assume the expiry date doesn't matter if you've got a valid visa, but I'm not 100 per cent sure...
The UK requires you to have a current and valid passport at the moment you apply for a Tier 2 visa. Current and valid seems to mean that the passport should be valid for the entire duration of your stay, although this kinda conflicts with the whole concept that passports do in fact expire. However, this is nothing to be worried about. As long as the passport doesn't expire it is considered a valid travel document. Indeed, this similar enquiry to the UK Home Office got the following reply:
As you are already aware, your passport must be valid when you apply for your visa and when you seek entry into the United Kingdom. However, you may wish to contact your airliner to see if there is any restrictions on validity of your passport at the time of travel.
Please be advised that when entering or re-entering the UK, a foreign national will be required to show a valid visa allowing them entry to the UK, for those categories where this is required, along with evidence that they are entering or re-entering for the same purpose.
So make sure you re-enter the UK on a valid passport and with a valid visa.
What you can (or should) do to be on the safe side is get a new passport, or at least apply for a new passport ASAP. Once you have a new passport, you can consider transferring your existing visa on it. Transferring the visa to the new passport isn't necessary according to the UK governmental website. All you have to do is to make sure they carry both passports with them upon entry in the UK.
You don’t have to transfer your visa - you can carry both your old and new passports when travelling to or from the UK instead.
You can, if you wish to do so, convert your visa into a Biometric Residence Permit if you are currently in the UK. Else, you can apply for a visa transfer online. For completeness sake note that visa transfers have a cost of several hundrend GBP.