My rough mental image is that, at transition elements, the outer electrons have several energies close to an other. Depending on the molecules, for instance the proportion of oxygen, only the shallower electrons participate, or the somewhat deeper participate too.
This representation is very incomplete, because the ability to bind depends on how the atom (or ion if you wish) will look like in the molecule, not just the lone atom prior to binding, and because several levels are available and rearrange, this is
hard to predict.
Why Fe, Co and Ni have the same usual valences, I ignore that.
This isn't limited to transition elements. C for instance can build CO or CO
2. It has [He]2s
22p
2 configuration, where 2s and 2p have the same energy in a hydrogen atom (the difference is really tiny) but differ a bit in a carbon atom due to electrons interactions.
As our world is complicated, you could have a look at how many oxidation states each element can have, beyond the most usual ones:
https://en.wikipedia.org/wiki/Oxidation_state#List_of_oxidation_states_of_the_elements