This is the same issue as described here (and in references therein). I suggest to read that answer and the linked discussions for an explanation of why this happens.
The workaround can be also the same as mentioned there:
foo2[x_] := With[{rule = Rule}, Table[rule[(unk /. log[var_] -> var), x], {unk, unks}] ] So that now
foo2[5] (* {n -> 5} *) Basically, it fools RuleDelayed (the one that results from SetDelayed, in DownValues[foo2]), so that it does not recognise the inner rule as such, and so does not rename xvar onin one part of the r.h.s.inner rule during the rule application.