I can't figure out why \d+ never gets to the point 12 but tries further to 56.
the regex (?=(\d+))\w+\1 never matches 123x12. First the lookaround captures 123 into \1. \w+ then matches the whole string and backtracks until it matches only 1. Finally, \w+ fails since \1 cannot be matched at any position. Now, the regex engine has nothing to backtrack to, and the overall regex fails. The backtracking steps created by \d+ have been discarded. It never gets to the point where the lookahead captures only 12.
Obviously, the regex engine does try further positions in the string. If we change the subject string, the regex (?=(\d+))\w+\1 does match 56x56 in 456x56.
https://www.regular-expressions.info/lookaround.html#:~:text=Lookaround%20Is%20Atomic
so far as I've understood, the lookaround does nothing but get a immutable capturing group at first, as "the regex engine forgets about everything inside the lookaround", and immediately passing it to "\1", in the first case 123x12, \1 is 123, and 456 for second case.