If a judge authorized to grant writs of habeas corpus willfully refuses to grant the writ when legally applied for, the judge shall forfeit to the party aggrieved $1,000 for each offense.