all the before-mentioned courts of the United States shall have power to issue writs . . . habeas corpus . . . . And . . . the justices of the supreme court . . . shall have the power to grant writs of habeas corpus for the purpose of an inquiry into the cause of commitment.—Provided, That writs of habeas corpus shall in no case extend to prisoners in
gaol, unless where they are in custody, under or by colour of the authority of the United States, or are committed for trial before some court of the same, or are necessary to be brought into court to testify.