§ 37.2-844 – Habeas corpus as means
A. Any person held in custody because of his mental illness may by petition for a writ of habeas corpus have the question of the legality of his detention determined by a court of competent jurisdiction. Upon the petition, after notice to the authorities of the facility or other institution in which the person is confined, the court shall determine in a courtroom of the county or city or in some other convenient public place in that county or city, whether the person has a mental illness and whether he should be detained.
B. Any proceeding to challenge the continued secure inpatient treatment of a person held in custody as a sexually violent predator under Chapter 9 (§ 37.2-900 et seq.) of this title shall be conducted in accordance with § 37.2-910.