Short answer. Whenever a person is illegally confined or detained, or their rightful custody is being withheld from someone entitled to it. The writ of habeas corpus extends to all such cases of illegal confinement or detention, except where another law expressly provides otherwise.
What the law says
Except as otherwise expressly provided by law, the writ of habeas corpus shall extend to all cases 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.
Rule 102, Section 1 — To what habeas corpus extends. Read the full provision →
The writ reaches illegal confinement broadly
The rule is written expansively: the writ shall extend to all cases of illegal confinement or detention by which any person is deprived of his liberty. This covers detention that lacks legal basis in the first place, whether by government authorities or by a private party, wherever a person's liberty is being unlawfully withheld from them without any proper legal justification whatsoever actually standing behind the confinement itself.
It also reaches wrongful denial of custody
The writ is not limited to confinement in the literal sense. It equally covers cases where the rightful custody of any person is withheld from the person entitled thereto — situations where someone with a legal right to custody of another person is being denied that custody, even without the confined person being physically locked up in the conventional sense of the word. This is what makes the writ useful in a broader range of disputes than physical imprisonment alone.
The rule yields where another law expressly provides otherwise
The opening clause — except as otherwise expressly provided by law — signals that this is the general rule, not the only rule. Where custody of a minor is what is actually at stake, a special rule now governs: A.M. No. 03-04-04-SC, the Rule on Custody of Minors and Writ of Habeas Corpus in Relation to Custody of Minors, effective May 15, 2003, applies specifically to that particular situation instead of the general rule stated here.
Why this matters for a detained relative
For an adult relative held without legal basis — not a custody dispute involving a minor — this general rule is the one that applies: illegal confinement or detention, of any kind, deprived of legal authority, is exactly what the writ of habeas corpus was built to address. Confirming that the detention genuinely lacks legal basis is the key question before pursuing this remedy, since a detention that does rest on legal authority is not something the writ reaches at all.