The result Fermat is using here is the following: if a number $n$ is represented primitively by the quadratic form $x^2 + my^2$, where $m = 1, \pm 2, 3$, then so is
any (positive) divisor of $n$ (primitively represented means $\gcd(x,y) = 1$).
Fermat had descent proofs for these claims. Lagrange later showed that if a number
$n$ is represented primitively by the quadratic form $x^2 + my^2$, then any prime
divisor of $n$ is represented by some (reduced) form with the same discriminant $-4m$.
In Fermat's examples, the class number is $1$, and the only reduced form with discriminant $-4m$ is then the principal form.

Gerry's idea will also work, and it is instructive to find out where the method of parametrization for $m=5$ differs from the case $m=2$.