Any court having jurisdiction of actions for divorce or nullity of marriage, separate support, or maintenance, or of any other proceeding in which the care and custody of any child is drawn in question, may issue a writ of habeas corpus to bring before it such child. The writ may be made returnable forthwith before the court by which it is issued, and, upon its return, said court may make any appropriate order or judgment relative to the child who may thus be brought before it.
Mass. Gen. Laws ch. 208, § 32