You have to use more indices to express the entry of $P^n$.
To be more precise for any matrix $P$ with entries $P_{ij}$, the entries of the matrix $P^n$, given by $(P^n)_{ij}$ are given by :
$$
(P^n)_{ij} = \sum_{a_1,a_2,...,a_{n-1} = 1}^n P_{ia_1}P_{a_1a_2}\ldots P_{a_{n-2}a_{n-1}}P_{a_{n-1}j}
$$
so the number of indices changes with the power. This formula can easily proved by induction, as you saw for the case $n=2$ to $n=3$ by substitution.
Note that the problem of having $n-1$ summations is solved by iterating over a different set that contains all the possible types of indices : this is why we can combine $a_1,...,a_{n-1}$ into one summation.
Furthermore, a very similar formula applies for the product of $n$ matrices in an admissible order (number of columns of left matrix equals number of rows of the right matrix). More precisely , if $A_i$, $i=1,...,n$ are $c_i \times d_i$ matrices such that $c_{i+1} = d_i$ for all $i=1,...,n-1$, then the product $\prod A_i$ will have entries given by a similar summation, which I leave you to figure out, where each $a_i$ in the index set will not vary from $1$ to $n$, but something else. The expression for entries of the power is a special case of this formula, which can also be proved by induction.