The U.S. Supreme Court has struck down a federal law based on what the justices called "stunning stereotypes" — among them that most men care little about their children born out of wedlock.

Under the law, a child born abroad to an unwed American mother automatically becomes a U.S. citizen if the mother previously lived in the U.S. for a period of at least one year.

In contrast, the child of an unwed father can't become a U.S. citizen unless the father has lived in the U.S. for a continuous period of five years, two of them when he was over the age of 14.

Now, the Supreme Court has ruled that the different gender lines drawn by Congress violate the Constitution's guarantee of equal protection of the law.

An immigrant seeking citizenship

The case was brought by Luis Ramón Morales-Santana, born in the Dominican Republic to unwed parents — a mother from the DR and a U.S.-citizen father who had been working on a construction project there.

Morales-Santana's father fell 20 days short of the U.S. residency required to qualify his son for automatic citizenship at birth, but the father took responsibility for the son; the parents eventually married and put the father's name on the birth certificate.

Morales-Santana came to the U.S. with his parents as a permanent resident. But in 2000, after he was convicted of several felonies, the government sought to deport him.

Morales-Santana then challenged the citizenship law as unconstitutional sex discrimination, and on Monday the Supreme Court agreed: The child of an unwed American mother cannot be granted automatic citizenship more quickly than the child of an unwed American father.

Justice Ginsburg center stage

Justice Ruth Bader Ginsburg wrote for the majority — and in many ways for her the opinion was a trip down memory lane.

Ginsburg cited decisions she briefed and argued as an attorney nearly 50 years ago — decisions that transformed the law and put gender discrimination nearly on a par with unconstitutional race discrimination.

This decision is a major victory for the justice, who for 20 years battled unsuccessfully for equal treatment of men and women seeking to pass citizenship on to their children. On Monday she was able to turn the corner.

It's the fourth time in two decades that the court has grappled with some version of this issue. In 2001, the justices upheld the differential treatment by a 5-to-4 vote, and twice the court failed to reach a majority ruling.

On Monday, however, the vote was 6 to 2 to require equal treatment of unwed mothers, fathers and their children. Joining in the Ginsburg opinion were not just the court's other liberals, but Chief Justice John Roberts and Justice Anthony Kennedy.

Breaking eggs to get to a six-justice majority

But the decision left what Ginsburg called the "vexing problem" of what to do next.

The rule in a typical case would be to extend the favorable treatment of one sex — in this case women — to men. But here, Ginsburg observed, favorable treatment for mothers was the exception to the general rule in the statute.

She said the court was not free to make the exception into the general rule. Instead, she said, it is up to Congress to set the same rule for everyone.

In the meantime, Ginsburg said, the law would have to be equalized by making unwed mothers abide by the tougher citizenship rules that in the past have applied to unwed fathers — which means Morales-Santana would not qualify for citizenship.

University of Chicago law professor Mary Anne Case says she suspects that it "broke [Ginsburg's] heart" to have to do it this way. "This is an omelet that they made by breaking some eggs," she said.

Still, the court for the first time has applied the concept of gender equality to the nation's citizenship laws.

Copyright 2017 NPR. To see more, visit http://www.npr.org/.