Why do all the lanthanides and actinides belong in Group 3B? To answer this, look at the difference between group 3B and 4B.
The 3B elements are the first elements to begin filling the d shell electrons in their electron configuration. The 4B group is the second, where the next electron is placed in the d2 shell.
For example, scandium is the first 3B element with an electron configuration of [Ar]3d14s2. The next element is titanium in group 4B with electron configuration [Ar]3d24s2.
The same is true between yttrium with electron configuration [Kr]4d15s2 and zirconium with electron configuration [Kr]4d25s2.
The difference between group 3B and 4B is the addition of an electron to the d shell.
Lanthanum has the d1 electron like the other 3B elements, but the d2 electron does not appear until element 72 (hafnium). Based on behavior in previous rows, element 58 should fill the d2 electron, but instead, the electron fills the first f shell electron. All the lanthanide elements fill the 4f electron shell before the second 5d electron gets filled. Since all the lanthanides contain a 5d1 electron, they belong in the 3B group.
Similarly, the actinides contain a 6d1 electron and fill the 5f shell before filling the 6d2 electron. All actinides belong in the 3B group.
The lanthanides and actinides are arranged below with a notation in the main body cell rather than making room for all these elements in the 3B group in the main body of the periodic table.
Because of the f shell electrons, these two element groups are also known the f-block elements.