I don't see a bug, in scripts your variables are in the same scope has the command line but inside functions like your doit function the scope is just that doit function.
size in yay is a variable, yay is a script
size in doit is a MATLAB function, doit is a function
Ok I must admit that something weird is going on after testing and reading the documentation, matlab seems to be confused about it, when we ask what's size MATLAB says it's a variable but when using size to do something it's the MATLAB function again, MATLAB functions seem to take priority.
Now catch is equal to 2 inside the function doit
Don't use variables with the same name as scripts or MATLAB functions, if you do use the same names you might get weird problems like the one you found.