I think it's because it takes less energy to store an electron in a half-filled or completely-filled d shell rather than a filled s shell. Like in Cr with the electron configuration [Ar]4s13d5, the last valence electron goes to the 3d shell instead of the 4s shell because it takes less energy to store it in 3d.
-hope this helps