It's a consequence of the definition of matrix multiplication. The proof can be done by induction.
For the induction step, write $M^k$ as $M^{k-1} \cdot M$, and then look at the $(i,j)$th entry, which is
$$(M^{k-1}\cdot M)_{i,j} = \sum_{\ell=1}^n (M^{k-1})_{i,\ell} \cdot M_{\ell,j}.$$
For a given value of $\ell$, $(M^{k-1})_{i,\ell}$ is the number of ways to get from $i$ to $\ell$ in $k-1$ steps, and $M_{\ell,j}$ is the number of ways to get from $\ell$ to $j$ in one step. Thus, $(M^{k-1})_{i,\ell} \cdot M_{\ell,j}$ is the number of ways to get from $i$ to $j$ in $k$ steps, if the penultimate vertex is $\ell$.
Now, the penultimate vertex must be one of $1, 2, \ldots, n$. Adding up these products counts how many ways there are to get from $i$ to $j$, since a walk has exactly one penultimate vertex.