> shouldn't you be creating this metatable as an upvalue?

No. This should not be created as an upvalue.

To be an upvalue we'd have to declare the metatable outside of the function. Doing this means we have to declare the lookup table outside of the function as well. Which means the lookup table is share across all case insensitive tables. If the lookup is shared than all tables will clobber each others case preserved keys.