I don’t know why the Gnostics specifically thought that Jesus was married, but I’ll go over a few of the evidences people use in favor of Jesus being married. Since the majority of peole who believe that Jesus was married would say that he was married to Mary Magdalene, I’ll address whether Jesus and Mary Magdalene were married.
–Evidences in Favor of Jesus being Married–
Jews in Jesus’ day were basically all married by a certain age. For Jesus to be unmarried would have been VERY unusual; virtually unheard of. However, some philosophers at the time speak of a few men who willingly choose not to marry, so there may have been a growing trend to be single.
From scripture, we know that Mary Magdalene (among other women) followed Jesus. Some are mentioned in Luke 8:1-3. What is strange here is that rabbis at this time didn’t typically include women in their followings or teachings. What is special about Mary Magdalene is that she appears to be one of Jesus’ closest followers, and is even a witness to seeing Jesus rise from the dead.
Additional text about Mary Magdalene’s close relationship with Jesus can be found in extra-canonical gospels, such as the gospels of Thomas, Peter, and Phillip. (However, none of these gospels can provide a reason to believe that Jesus and Mary were married)
–Evidences Against Jesus being Married–
We don’t need any, because there’s nothing to talk about. I can’t prove unicorns don’t exist, neither can I prove that Jesus and Mary weren’t married, but the lack of evidence in favor of unicorns or the marriage suggest that neither exist.