https://en.wikipedia.org/wiki/Hund%27s_rules
http://hyperphysics.phy-astr.gsu.edu/hbase/atomic/hund.html
The first two rule are mostly caused by Coulomb interaction.
The third is caused by spin-orbit coupling.