Iron can lose its two 4s electrons to get a valency of +2, or it can lose the two 4s electrons and a 3d electron to get a valency of +3.
The four s electrons are the greatest distance from the nucleus. Even though the energy level of the 3d electrons start out higher than the 4s electrons the 4s electrons are the first to be removed.
This results in a valance of +2 .
Iron has six 3d electrons. By losing two 4s electrons and one 3d electron, iron gets a valency of +3·.