As mentioned earlier scholars have difficulty with this passage. It is so much what we want Jesus to be that we have to keep it. But scholars see how jarring it is in the place it is and have doubts.
For me I can see the point made by the editor of the New Jerusalem when they want to put it in Luke. John’s gospel seems to be committed to inserting little comments relating to Jesus’ motivations — John seems afraid that some enigmatic act on the part of Jesus mat throw an ill light on his thesis that Jesus was/is God Incarnate. Luke and the Synoptics on the otherhand seem far more interested in disparaging asides about the opposition to Jesus’ message. And so:
“Teacher, this woman was caught in the very act of committing adultery. Now in the law Moses commanded us to stone such women. Now what do you say?”
They said this to test him, so that they might have some charge to bring against him.
For the author of this passage it is very clear this was not simple academic question in theological debate. This was a power move to undermine and discredit and eventually kill a wisdom teacher and a prophet.
Jesus’ response. Drawing in the dust. I have no idea where it comes from. In the early days and in the face of persecution Christians would casually draw fish symbols to identify themselves to one another. Perhaps the story began in one of Jesus’ enigmatic sayings let him who is without sin . . . And the narrative bits got added by later Christian prophets. I don’t know.
The message itself feels almost more like James and the pastoral letters than the gospels.
For whoever keeps the whole law but fails in one point has become accountable for all of it. For the one who said, “You shall not commit adultery,” also said, “You shall not murder.” Now if you do not commit adultery but if you murder, you have become a transgressor of the law. (James 2:10-11)