In which ring do you work, in $K$ or in $K[A] \subset M_n(K)$ the commutative subring generated by the matrix $A$. If you work in $K$ you certainly cannot consider $A$ as an element of the ring. If you work in $K[A]$, what is the meaning of $A$ in $det(A-\lambda I_n)$, is it a scalar ?
There is however, a trick which can make the proof correct. We know (Cramer Formula)that for every matrix $M$, on has $M.\tilde M= det(M). Id$, where $\tilde M$ is the transpose of the cofactor matrix of $M$. Applying this formula to $M=A-\lambda Id$ in the ring $K[\lambda]$ we get :
$(A-\lambda. I_n)(A_0+\lambda A_1+\lambda ^2 A_2++\lambda^{n_1}A_{n-1})= p(\lambda) Id$. This identity is written in $M_n(K[\lambda])$.
If $p(\lambda)=a_0+a_1\lambda+a_2\lambda ^2+..$, then:
$AA_0= a_0 Id$, $AA_1-A_0=a_1 Id$, $AA_2-A_1...=a_2 Id$ etc.
Therefore $p(A)=a_0Id+a_1 A+a_2A^2+...=AA_0-AA_0+A^2A_1-A^2A_1+..=0$ Note that we use the fact that the matrices $A.A_{i+1}-A_i$ are proportional to $Id$ and commute with $A$.