Suppose I have two operators $J^2$ and$J_z$ where they represent the length of angular momentum and its $z$ component respectively.
Sure, it's legal to write new operators like $J^2-J_z^2$ or $J_x+J_z$ but it's not legal to write $J^2-J_z$ because they don't have the same physical dimension.
However, I want to know what prevent them from becoming operators in ket space mathematically.