Filling out electronic orbitals follows the Aufbau principle, meaning that the lowest energy orbitals are filled out first. In some rare cases whilst this principle is used to write the electronic configuration, the electrons can re-arrange to obtain an, even more, energy favoured conformation.
This phenomenon happens when the d orbitals have either 4 electrons or 9 electrons. When this happens it is more energy favourable to remove an electron from the full s-orbital, so that the s orbital would be half full and the d-orbital would now have either 5 electrons, making it half full, or 10 electrons, making it a full d-orbital.
1s2 2s2 2p6 3s2 3p6 4s2 3d4 becomes
1s2 2s2 2p6 3s2 3p6 4s1 3d5
1s2 2s2 2p6 3s2 3p6 4s2 3d9 becomes
1s2 2s2 2p6 3s2 3p6 4s1 3d10