The writ is not issued where the (a) detention is lawful, (b) the proceeding is for contempt of a legislature or a court, (c) detention is by a competent court, and (d) detention is outside the jurisdiction of the court.