When a criminal or equity court of this State annuls a marriage, or when an equity court of this State decrees an absolute divorce for a reason that makes the marriage void ab initio, the court in the decree shall declare each child of the marriage to be a legitimate child of the parties to the marriage.