You’re mixing up the Infancy Gospel of Thomas with the Gnostic Gospel of Thomas. They’re different. The infancy gospel is not gnostic in origin but it is extremely weird because nobody really knows why it exists. Proposals have even included that it’s a children’s book, but that’s probably not true because Jesus acts incredibly un-Christlike in it and no parent wants their kid to act like Jesus does in it (being rebellious to authority, getting in petty scraps, not listening to his parents, etc.). But it’s not canonical in part because it wasn’t as widespread as even something like the Protoevangelion of James (where we get basically all Christmas imagery and narratives about Mary) and there’s obvious discomfort trying to fit the Jesus of the IGT alongside the Jesus of the canonical gospels.
But it’s not gnostic and you’re thinking of a different gospel also under the name of James.