Not sure if I see what the problem is. First run subquery T1:
SELECT num, ROW_NUMBER() OVER (ORDER BY num) FROM @a GROUP BY num;
You get two lines:
dan 1 fran 2
Now join it with the number num = num, you will get 4 lines, 2 for each individual value. What is your actual goal? Perhaps you should use ROW_NUMBER () outside?
The order of materialization depends on the optimizer. You will find that other built-in modules (RAND (), GETDATE (), etc.) have similar inconsistent materialization behavior. There is not much you can do with this, and there is not much chance that they are going to “fix” it.
EDIT
New sample code. Write the contents of @a to the #temp table to “materialize” the NEWID () assignment for each unique num value.
SELECT num, id = NEWID() INTO
source share