A proposed reason for that is that the proto-gnostics of the Thomasine variety of Christianity (think Gospel of Thomas) had become a thing by the time John was written or compiled into its current state. These groups doubted that the Resurrection of Jesus was physical.
Even if not a direct repudiation of these beliefs (e.g. “Even your beloved Thomas knew the Resurrection was physical!”) , the idea of “doubting Thomas” could have thus taken root by then, and thus got incorporated into the stories.