O. Henry was noted for the surprise endings of many of his stories. In fact, short stories in which the effect depends upon a surprise ending are often referred to as "O. Henry stories." They have fallen out of fashion in recent years, but many of O. Henry's best stories are still anthologized and read in high school and college English literature classes because they are well-written and are good yarns.
"A Retrieved Reformation" is an excellent example of an O. Henry story because the reader is totally surprised. He believes that the expert safe-cracker Jimmy Valentine is sure to go to prison for doing something that is completely noble and unselfish. Jimmy has given up his life of crime. He is engaged to marry a lovely girl. He is completely reformed. Then, ironically:
Suddenly there was a scream or two from the women, and a commotion. Unperceived by the elders, May, the nine-year-old girl, in a spirit of play, had shut Agatha in the vault. She had then shot the bolts and turned the knob of the combination as she had seen Mr. Adams do.
The reader expects the story to end with Jimmy being led off too prison in an ironic ending similar to that of O. Henry's "The Cop and the Anthem," in which Soapy decides to reform completely and is then arrested for vagrancy and sent to jail on Blackwell's Island. But O. Henry gives another ironic twist to the ironic twist in "A Retrieved Reformation." After Jimmy has exposed his true identity by using his safe-cracking tools to free the little girl from the bank vault, he finds himself facing arrest by the detective Ben Price.
"Hello, Ben!" said Jimmy, still with his strange smile. "Got around at last, have you? Well, let's go. I don't know that it makes much difference, now."
And then Ben Price acted rather strangely.
"Guess you're mistaken, Mr. Spencer," he said. "Don't believe I recognize you...."
Jimmy Valentine's reformation seemed to have been in vain, but it was "retrieved" at the last minute when the detective rewarded him for his unselfishness and courage by letting him walk away a free man.
It should be noted that O. Henry opens "A Retrieved Reformation" inside a prison. This is to show what hard lives prisoners lead, and to let the reader understand what Jimmy would be going back to, probably for many years.
It was quite a coincidence that Jimmy Valentine, world's greatest safe-cracker, just happened to be in the bank with his whole bag of tools when a little girl got locked into a burglar-proof vault--but O. Henry, like the great Charles Dickens, never concerned himself about being accused of inventing improbable coincidences.