ところが、引き返すとなったとたん、痛みがましてきた。
However, just as it became time to go back, the pain increased still further.
I don't understand the grammar of the part in bold. My translation is a best guess.
I'm familiar with the use of とたん to mean 'just as', and なる to mean 'become', but I don't know any grammar where と+なる can attach to a verb.