It has to due with energy of the orbits and the distance the electron cloud density needs to travel.
The 4s orbital has a spherical orbital. The electron density has to move randomly in a sphere.
The 3d orbital has a clover leaf orbital The electron density has to move randomly in a four loped pattern.
Even thought the 4s is further from the nucleus it requires less energy for the first electron to occupy the 4s than to occupy the 3d orbitals. As the number of electrons and protons increases the 3d orbitals are drawn closer to the nucleus decreasing the amount of energy required to occupy a 3d orbital.
When the 3d orbitals are completely filled the 5 3d orbitals are drawn completely into the third shell leaving the 4s orbitals as the location of the valance electrons.