so y will be the number of columns in X.
so the variable referring to columns in X will be i
but i is being used as a row index, not as a column index.
Your code does not compute matrix multiplication, unless perhaps your matrices are size 2 (and even then it is likely to get indices out of range.)
For matrix multiplication, z(i,j) should be the sum of the products of row i of X together with the transpose of column j of Y.