Suppose a tenant has access to their rented UK flat using an electronic card system which is maintained by the landlord. Is it legal for the landlord to use the system to purposely lock the tenant out in order to force them to visit (for instance, to pick up a new replacement card or for some other reason). If not, what specific law is being broken?
The right to quiet enjoyment means that you have a right to exclusive and private occupation of your home. As a tenant, you have the right to control who enters and visits the property, which includes the landlord, the managing agent, any service companies that do repairs, etc.
It's a bit of a shady area, but most of the times you can even change the locks and keep the keys to yourself. Your landlord will require access on numerous occasions, like inspections, repairs, etc. However, if you allow them access without being too difficult, you can keep the keys to yourself. It's unlikely they can get a court order for you to provide keys to them because it goes against your right of quiet enjoyment.
However, it's absurd that your landlord locks you out entirely, forcing you to do whatever it is to gain back access.
You should send them an official letter, notifying them that they are seriously breaching the tenancy agreement and that you have a right to exclusive access and occupation of the property. Threaten them with legal action if this problem is not resolved immediately. It's likely they will not do it again.