There are two separate requirements: facing the qibla correctly and not standing ahead of the imam in a manner that invalidates following.
Where the imam and follower face different internal directions, their bodily arrangement alone does not establish the same kind of precedence that applies when both face the same side. This explains the text’s ruling of validity.