Inside your logpdf! function, Y = lu(x) rebinds Y to a new value lu(X), but only within the function’s local scope. This doesn’t affect the global Y because it’s a different Y that only exists inside your function. Your local Yshadows the Y passed as the argument.
And if you find all this a bit confusing, you’re not alone: