Any individual who has been admitted to a State residential center or any person on behalf of the individual may apply at any time to a court of competent jurisdiction for a writ of habeas corpus to determine the cause and the legality of the detention.
Md. Code, HG § 7-506