MEXICO CITY (AP) — Mexico’s high court has struck down a clause in the capital’s family code automatically granting custody of young children to mothers in divorce cases.

The Supreme Court found Thursday that the rule governing custody of kids under 12 years old is unconstitutional for making a distinction on gender.

The ruling is based on the principle of equality and the higher interest of minors. It says the unconstitutional language violates the latter by taking away judges’ discretion to consider the individual circumstances of each case to determine which parent is best equipped to care for a child’s needs.

It also says the prior presumption in favor of mothers “not only reaffirmed traditional gender stereotypes but deepens the role of the women-mother and impedes the eradication of the traditional conception of femininity.”