While there might also be other stuff in play in this example, the basic concept that explains the behavior is that for Zig vars are not considered comptime known, while consts are (when hardcoded to a literal or the value is otherwise comptime known).
In general I think the idea is that Zig is being conservative, a var could have its pointer taken and be modified from somewhere else, while consts cannot be modified even if you take their pointer.
So in var foo: u8 = 2; the value of foo is comptime-known, but foo itself could still be modified at runtime.