Nothing here is undefined, and there is no reason for there to be a syntax error.
Your loop iterates the outer vector by value, then sorts the local copy of the inner vector. It's pointless, but it's not naughty.
I recently came to know that when a data inside range based for loop is modified, the result is undefined.
You can't structurally modify the thing you're iterating over, true, as that breaks the iteration.
But that's not what you did. Even if you'd written auto& v : arr, and thus modified the values of the inner vectors, you're still not performing any operation that disrupts the iteration of the outer vector arr.
Don't write arr.clear() inside the loop, though!
Why is modification of auto iterated data not a syntax error?
Even if your program had undefined behaviour, that's never a syntax error, and often not even a runtime error.
But if there were a blanket rule stating that no mutating operations could ever be performed inside a range-based for loop, rest assured the semantics of the language would probably mandate a compile-time error to stop you from doing it (like how you cannot build a program that modifies a const int directly).
int* pa; {int a = 5; pa = &a;} *pa = 1;