In all writs of habeas corpus sought on account of the detention of a spouse or child, the court on hearing all the facts may exercise its discretion as to whom the custody of the spouse or child shall be given and shall have the power to give the custody of a child to a third person.
OCGA § 9-14-2