The writ of habeas corpus is the remedy to be used when any person is restrained in his liberty. Habeas corpus is not a second appeal or a way around an unfavorable decision on direct appeal.An application for a writ of habeas corpus asks a court to overturn your conviction because of a state or federal constitutional violation. In a writ of habeas corpus, a defendant seeks to establish that his or her prison sentence is illegal. This can be done in two ways. In Texas, the state writ of habeas corpus is a legal mechanism that allows individuals to challenge their detention or imprisonment. In Texas, a writ of habeas corpus is a court order in which the judge demands a law enforcement agency to produce a detainee for a court hearing. Fill out the Petition for Writ of Habeas Corpus to Return Child. Successfully petitioning for a Writ of Habeas Corpus may result in a reduction of a prison sentence, a new trial, or even a person's freedom. An application for a Writ of Habeas Corpus is filed when a person seeks relief from unlawful detention or imprisonment.