There is no general maximum length of time for which someone can be detained for immigration purposes. This applies irrespective of the basis of the individual’s detention.
Published Home Office policy, available via the link below, is clear, however, that detention is only ever used for the shortest period necessary, and there must be a realistic prospect of removal within a reasonable timescale. During this time, decisions to maintain detention are reviewed regularly and whenever there is new evidence of removability or vulnerability. Whilst in detention, any health and welfare needs of a detained person are met through the provision of appropriate services.