Delay in transfer from prison to hospital

an individul is awiting a bed at a psychiatric hospital howvwer a bed has not been made available any where on the country, the judge has had a report from dr stating he is unwell and needs a bed but it has now bwwn two years and a bed has and will nto be made how long can the person who is in prison be detained within a priosn rather than a hospital is this lawfull or unlawfulll