First select the elements of the main diagonal.
There $p-1$ ways to select them so that their product is $1$.
If the product is $1$ the product of the elements of the other diagonal must be $0$. There are $2p-1$ ways to select them so at least one of them is a multiple of $p$.
This gives us $(p-1)(2p-1)$ matrices.
There are $p^2-p+1$ selections in which the product of the diagonal is not $1$.
No matter what the product of the diagonal is, the product for the other diagonal shall be fixed, and will be non-zero. There are $p-1$ ways to choose them so that they give the selected product.
So we have $(p-1)(2p-1)+(p^2-p+1)(p-1)=(p-1)(p^2+p)=p^3-p$ such matrices.