At the beginning of a tenancy the landlord should always check that the tenant has the Right to Rent in the UK by checking certain details such as their passport and (if applicable) their visa.
You can see our separate article on a landlord's 'right to rent' duties here:
What happens if a tenant's visa runs out during the tenancy?
Even if you have carried out your 'Right to Rent' duties at the start of the tenancy to ensure the tenancy is legal, it may be that your tenant(s) visa runs out during the term of the tenancy agreement.
If this happens you should refer to the Government guidance on what to do in this instance. You can find that here:
The general guidance is that as long as you are taking reasonable steps to avoid this situation, or to end the tenancy within a reasonable amount of time, then you should be able to build a defence against the offence of renting to someone that doesn't hold the right to rent in the UK.
The Government also provides a free helpline: 0300 069 9799.