Is idempotency, $\rho^2=\rho$, a necessary and sufficient condition for $\rho$ to be a pure state?
THEOREM 1 If $\rho$ is a density matrix (i.e., a positive, unit-trace, trace-class operator, also in an infinite dimensional Hilbert space), then $\rho$ is a pure state iff $\rho^2=\rho$.
Proof. If $\rho$ is pure, then $\rho^2=\rho$. Let us prove the converse implication. Suppose that $\rho^2 = \rho$ ($\rho^2$ is trace class if $\rho$ is because the set of trace class operators is a $^*$ ideal of the $C^*$-algebra of bounded operators) then $$0=\rho^2-\rho = \sum_{j} (\lambda_j^2 -\lambda_j) |\psi_j\rangle \langle \psi_j|\tag{1}$$ where, from the definition of density matrix (positive unit-trace trace-class operator) $$\lambda_j \in [0,1]\tag{2}$$ and $$\sum_j \lambda_j =1\tag{3}\:.$$ Let us assume that there are at least two $j\neq j'$ with $\lambda_j,\lambda_{j'}>0$. We conclude from (2) that both $\lambda_j^2-\lambda_j<0$ and $\lambda_{j'}^2-\lambda_{j'}<0$. Since $\langle \psi_k|\psi_h \rangle = \delta_{hk}$, (1) leads to $$0 = \langle \psi_{j'}|0 \psi_{j'}\rangle = \lambda_{j'}^2-\lambda_{j'} <0$$ that is impossible. We conclude that the assumption that there are at least two $j\neq j'$ with $\lambda_j,\lambda_{j'}>0$ is untenable so that $\rho = |\psi_j\rangle \langle \psi_j|$. $\Box$
With a similar route one easily proves that
THEOREM 2 If $\rho$ is a density matrix (also in an infinite dimensional Hilbert space), then $\rho$ is a pure state iff $tr(\rho^2)=tr(\rho)$ ($=1$).
Proof. If $\rho$ is pure the thesis it trivial. Let us pass to the converse implication. Since $\sum_j \lambda_j =1$ and $\lambda_j\in [0,1]$, if more than one $\lambda_j$ does not vanish, every $\lambda_j$ is strictly less than $1$, so that we have in particular $\lambda^2_j < \lambda_j$ for all $j$, which implies $\sum_j \lambda_j^2 < \sum_j \lambda_j$. This meas that if $tr(\rho^2) = tr(\rho)$, then only one $\lambda_j$ does not vanish so that $\rho$ is pure. $\Box$