A patient accused of hijacking a car after trying to seize control of an ambulance as part of a “bizarre rampage” must remain in custody, a High Court judge has ruled.