IiT is absolutely false that women automatically get custody. Women never had a right to custody. The law decided that a tender year doctrine would be a good idea. From childbirth to about kindergarten, a child could temporarily reside with its mother b/c judges decided that the child was not doing much in the world. Once the child reached early school age, the father resumed total control. The father decided on education, governess, etc. Women were viewed incapable of raising their children. With the focus on the Equal Protection Clause, the courts adopted a functional approach.
Err... What country do you live in? If the United States, you must be talking pre-1960s. The feminist movement changed everything in family law to where now fathers are treated as second class citizens. Nowadays, men are completely discriminated against in family court based solely upon their gender.
In the overwhelming majority of cases, women DO automatically get custody no matter how old the children are.