The High Court has ruled that the government's policy of discharging untested hospital patients into care homes at the start of the pandemic was "unlawful".