I suggest the book Annulment: The Wedding That Was by Michael Smith Foster. It’s a very good book on the topic of the Church’s teaching on marriage and nullity.
Matthew’s gospel brings up the idea of a marriage being invalid based on an illicit marriage (one between close kinship)-- it is often mistranslated as “unchastity” or even “adultery”.
The Epistles discuss the dissolution of the bond-- not the same as nullity-- via the Petrine or Pauline Privilege. So, the idea of the Church binding and loosing in cases of marriages goes all the way back to the bible.
The early Canons of various Councils begin to develop regulations regarding marriage-- and it would seem to follow that “nullity” would be a concept developing right along with it for if someone transgressed the Canon their marriage would not be valid.
For example the Canons of Elvira from c. 306 AD have many regulations regarding marriage.