Protoevangelio de Santiago
The first to offer a solution was the apocryphal Gospel of James, written about 150 AD. The original gospels never refer to Joseph's age, but the author presents him as an old man chosen by lot (i.e., by God) to watch over the Virgin. Jesus' brothers are presented as Joseph's children by an earlier marriage, and his years and righteousness explain why he has not yet had sex with his wife: "I received her by lot as my wife, and she is not yet my wife, but she has conceived by the Holy Spirit."