Rightful Custody Rule

A writ of habeas corpus CANNOT be issued once person is charged with a criminal offense. Under Section 1, Rule 102 of the Rules of Court, the writ of habeas corpus extends to all case of illegal confinement or detention by which any person is deprived of his liberty, or by which the rightful custody of any person is withheld from the person entitled thereto.
The remedy of habeas corpus has one objective: to inquire into the cause of detention of a person, and if found illegal, the court orders the release of the detainee. If, however, the detention is proven lawful, then the habeas corpus proceedings terminate. (In the Matter of the Petition for Habeas Corpus of Kunting; G.R. No. 167193, April 19, 2006)