Since $B=P^{-1}AP$, you only need to prove that for every invertible matrix $U$, $UA$ and $AU$ have the same rank as $A$. WLOG, consider $UA$. Since $U$ is invertible, $U=E_1\cdot\ldots\cdot E_n$ where $E_i$ is an elementary matrix. Then $UA=E_1\cdot\ldots\cdot E_nA$, so $UA$ is obtained from $A$ by a sequence of elementary row transformations. Since elementary row transformations do not change the rank, we are done.
An alternative proof. If $c_1,...,c_n$ are columns of $A$, then $Uc_1,...,Uc_n$ are columns of $UA$. Since $U$ is invertible columns $c_{i_1},...,c_{i_k}$ are linearly independent if and only if $Uc_{i_1},...,Uc_{i_k}$ are linearly independent. Since the rank is the maximal number $k$ such that there are such $i_1,...,i_k$, we are done.
Another alternative proof of the original statement. Let $A$ be the matrix of linear transformation $T$ of a vector space $V$ with basis $e_1,...,e_n$. Then $P^{-1}AP$ is the matrix of the same linear transformation in the basis $P^{-1}\{e_1,...,e_n\}$. The rank of $A$ and the rank of
$P^{-1}AP$ are equal to the dimension of the space $L(V)$, so these ranks are equal.