Stray memory, when you’re doing complex expressions like these, particularly if you’re using square brackets, you need to disable the ‘enable substitutions’ in the dynroute.
I tested your expression and it’s working for me:
Up unitl the 3 min mark:
[[2024-06-11 10:21:56] VERBOSE[29594][C-00000040] pbx.c: Executing [s@dynroute-2:2] Set("PJSIP/7010-00000089", "dynroute=0") in new stack
and after the 3 min mark
[2024-06-11 10:22:29] VERBOSE[30357][C-00000041] pbx.c: Executing [s@dynroute-2:2] Set("PJSIP/7010-0000008c", "dynroute=1") in new stack