You need to test
$? instead, which is the exit status of the previous command.
passwd exits with 0 if everything worked ok, and non-zero if the passwd change failed (wrong password, password mismatch, etc…)
passwd while [ $? -ne 0 ]; do passwd done
With your backtick version, you’re comparing passwd’s output, which would be stuff like
Enter password and
confirm password and the like.