A convicted mentally ill man whose release from the Central Mental Hospital posed potentially "catastrophic" risk to himself and others was lawfully made a ward of court days before his sentence for serious violent offences was due to end, the Supreme Court has ruled.