Section 25. This chapter shall not affect the power of the supreme judicial court, or the superior court, or a justice thereof, to issue a writ of habeas corpus in its discretion, and thereupon grant bail to a person for whatever cause he has been committed or restrained, or to discharge him as law and justice require. The court shall have no power to issue a writ of habeas corpus, at its discretion for—a person who has been committed by the governor and council, the senate, or the house of representatives in the manner and for the causes mentioned in the constitution, or a person who is imprisoned or restrained of his liberty pursuant to a criminal conviction.
This chapter shall not affect the power of any court or magistrate to issue a writ of habeas corpus, when necessary to bring before it a prisoner for trial in a pending criminal case; or to bring a prisoner to be examined as a witness in a suit or proceeding, civil or criminal, pending before the court, if the personal attendance and examination of the witness is necessary for the attainment of justice.