Answer
The condition is that if the expression is $A^2$ + $B^2$ then 2AB should be a perfect square.
Work Step by Step
If the expression is $A^2$ + $B^2$ then it is is solved as
$A^2$ + $B^2$ = $(A+B)^2$ − 2AB
which can then be factored into
$A^2$ + $B^2$ = (A + B + $\sqrt(2AB)$) (A + B − $\sqrt(2AB)$)
So, if 2AB is a perfect square then $\sqrt(2AB)$ is rational and the factors will be rational.
For example, if the expression is
$x^4$ + 4$y^4$ then the factors are
($x^2$ + 2$y^2$ + 2xy)($x^2$ + 2$y^2$ − 2xy)
as 2AB = 4$x^2$$y^2$ is a perfect square.