In my work I have spotted something "weird". Consider the matrix
\begin{align*} M_{ij} =1-\delta_{ij}. \end{align*} I want to find $ M^{2} $ in terms of its components. So \begin{align*} (M^{2})_{ij} =(M M)_{ij}& =M_{ia}M_{aj} \tag{1}\\ & = (1-\delta_{ia})(1-\delta_{aj}) \tag{2}\\ & =1+\delta_{ia}\delta_{aj}-\delta_{ia}-\delta_{aj} \tag{3}\\ & =1+\delta_{ij}-1 -1 \tag{4}\\ & =-1+\delta_{ij},\tag{5} \end{align*} however, this is clearly wrong, as consider $ n=2 $ , in which case we have \begin{align*} \begin{pmatrix} 0 & 1 \\ 1 &0 \end{pmatrix} \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} =\begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} . \end{align*} A guess where this goes wrong is from $ (1) $ to $ (2) $ as expanding $ (3) $ gives $ k $ as a free index, over which I have summed over. I did so because I couldn't leave it since it is a dummy variable. My best guess is that I am simply not allowed to go from $ (1) $ to $ (2) $ but I am not sure as to why that is.
If anybody could shine some light on this I would greatly appriciate it.
The $1$ in the definition is a matrix, not a number, and should be written as $1_{ij}$. ($J_{ij}$ would be better because the matrix of all ones doesn't act like the multiplicative identity, but I will leave it as $1_{ij}$.) Not writing the indices here causes problems later.
Following your derivation, we get \begin{align*} M_{ij} =1_{ij}-\delta_{ij}, \end{align*} and computing $M^2$, we get \begin{align*} (M^{2})_{ij} =(M M)_{ij}& =M_{ia}M_{aj} \tag{1}\\ & = (1_{ia}-\delta_{ia})(1_{aj}-\delta_{aj}) \tag{2}\\ & =1_{ia}1_{aj}+\delta_{ia}\delta_{aj}-\delta_{ia}1_{aj}-1_{ia}\delta_{aj} \tag{3}\\ & =n 1_{ij}+\delta_{ij}-1_{ij} -1_{ij} \tag{4}\\ & =(n-2) 1_{ij} +\delta_{ij},\tag{5} \end{align*} where we see the important error occurred in equation 4, where $1_{ia}1_{aj} = n 1_{ij} \neq 1_{ij}$