The person accused of a shock random stabbing will be released from custody into a hospital stay, a court has been told.