3d5 is more stable than 3d6 or 3d4 4s2
this is due to columbic repulsion (pic)
and exchange energy (pie)
columb's law says the force is proportional to the product of the charges over the distance squared.
The d have 5 orbitals , each orbital may hold a maximum of two electrons
the lowest energy that an orbital can have ( and thus most stable ) is when the electrons are far apart
thus:
2 electrons in same orbital higher E than 2 electrons in different orbitals
furthermore, electrons may exchange, and move to different orbitals, which means lower energy still.
The net result is having 5e- in 3d is lower in energy than having 2 in 4s.