It is helpful to consider the case in respect of the relevant period, which is the period of detention, being continuous, within which the qualifying order was made.
A patient’s relevant period may have begun long before the qualifying order is made, with a simple arrest, s.136 detention, s.2 or other form of detention, but as long as that period of detention is continuous, the material time for purposes of establishing residence is when the relevant period began.
If there had been an earlier break in the period of detention, for example, a period of voluntary admission, as is sometimes the case in long treatment stays, then the relevant period starts when a detention is re-imposed, almost invariably a qualifying one; and on those occasions, it will be necessary to consider their residence at that time, and not when they first came into hospital.
It is on those occasions that patients in my experience most commonly lose their original addresses, for all sorts of reasons, and risk becoming resident at the material time in the hospital where they were voluntarily admitted immediately prior to the new order being imposed, as per the judgement in Sunderland.
Patients who were genuinely of no fixed abode at the material time are the responsibility of the area where they are sent on discharge (s.117.3.c).
If nobody will accept the discharge at that point, then the local authority where the patient actually is, so usually for the area of the hospital itself, may have to accept practical responsibility under Reg. 2(3)b of the Care and Support (Disputes Between Local Authorities) Regulations 2014.
None of this is perfectly described in statute, it has to be said, even though s.117(3)a speaks of immediately before being detained, and not of immediately before being detained under a qualifying section. Worcestershire I do not think has tidied this up, continuing to speak of detention under the qualifying section (para.44 & 53) and not about when the period of detention within which the qualifying order was made began.