On the basis of the story's absence from key early NT manuscripts, the scholarly consensus is that it is a later addition to the Gospel of John. The most commonly respected conjecture about its source derives from an allusion by Papias (c. 60-120 AD) to a story in the Gospel of the Hebrews (c. 105-125 AD) about Jesus and a woman "accused of many sins." That seems right to me, but the problem is that we don't have the whole Gospel of the Hebrews today, but only several fragments of it and must rely on early church Fathers like Eusebius who do have this Gospel and offer allusions to it. According to
Eusebius of Caesarea (in his
Ecclesiastical History, composed in the early 300s), Papias (circa AD 110) refers to a story of Jesus and a woman "accused of many sins" as being found in the
Gospel of the Hebrews, which might refer to this passage or to one like it. Papias is early enough to claim access to the eyewitness testimony of a couple of Jesus' disciples and their immediate successors. So I think the story has an impressive claim to historicity.
But this issue leads to a broader and more interesting question. Oral tradition about Jesus' words and deeds survives well into the late 2nd century and many of these extracanonical sayings have an intriguing claim to authenticity. So I like to apply some of the criteria applied to the quest for the historical Jesus to these sayings to determine how this unknown material might shed more light on Jesus' teaching.