If $A = P^{-1}BP$, then
$\begin{align*} p_A(x) &= \det(xI - A) = \det(xI - P^{-1}BP) = \det (P^{-1}xIP - P^{-1}BP) = \det \big(P^{-1}(xI - B)P\big) = \\ &= \det P^{-1} \cdot \det(xI - B) \cdot \det P = \det(xI - B) \cdot \det P^{-1} \cdot \det P= \\ &= \det(xI - B) (\det P)^{-1} \cdot \det P = \det(xI - B)= p_B(x) \end{align*} $
Note that we don't really move $P^{-1}$ around; we apply the product property of determinants: $\det(AB) = \det A \cdot \det B$, and since the determinant is a real number, you can move it around because the real numbers are associative and commutative with respect to multiplication.
Now, why does $xI = P^{-1}xIP$?
We call scalar matrices all matrices of the form $kI$, where $k$ is a scalar (note that these matrices have zeroes everywhere except on the diagonal, which has all its entries equal to $k$). It turns out that scalar matrices commute with every matrix, that is, for any matrix $A$, $(kI)A = A(kI)$. (Actually, there are no other matrices that commute with all the matrices.)
Let's prove this equality entrywise; $n$ stands for the appropriate dimension of the matrix. The important thing to note in both cases is that the matrix $kI$ has all zeroes except in the diagonal, so the sums reduce to only one term:
$\displaystyle \big((kI)A\big)_{ij} = \sum_{l=1}^n (kI)_{il}A_{lj} = kA_{ij}$ (if $l \neq i$, then $(kI)_{il} = 0$; the only remaining term is with $l = i$)
$\displaystyle \big(A(kI)\big)_{ij} = \sum_{l=1}^n A_{il}(kI)_{lj} = A_{ij}k$ (if $l \neq j$, then $(kI)_{lj} = 0$; the only remaining term is with $l = j$)
Then we have $\big((kI)A\big)_{ij} = \big(A(kI)\big)_{ij}$ for all $i$, $j$, so $(kI)A = A(kI)$. And in our particular case, since $xI$ is a scalar matrix, $P^{-1}(xI)P = (xI)P^{-1}P = (xI)I = xI$.