Under the Mental Capacity Act, restraint of a person who lacks capacity is lawful only if it is necessary to prevent harm to them and proportionate to the likelihood and seriousness of that harm. It must be the least restrictive option and reviewed regularly.
If a person who lacks capacity is under continuous supervision and control and not free to leave (the "acid test" from Cheshire West, 2014), they are deprived of their liberty and this must be authorised, currently through the Deprivation of Liberty Safeguards (to be replaced by the Liberty Protection Safeguards).