WASHINGTON (AP) — Supreme Court Justice Elena Kagan on Monday cautioned that courts look political and forfeit legitimacy when they needlessly overturn precedent and decide more than they have to.

Speaking less than three months after a five-justice conservative majority overturned Roe v. Wade’s constitutional guarantee of abortion access, Kagan said the public’s view of the court can be damaged especially when changes in its membership lead to big changes in the law.

She stressed that she was not talking about any particular decision or even a string of rulings with which she disagreed.

Still, her remarks were similar to points made in dissenting opinions she wrote or contributed to in recent months, including in the abortion case.

“Judges create legitimacy problems for themselves … when they instead stray into places where it looks like they’re an extension of the political process or when they’re imposing their own personal preferences,” Kagan said at Temple Emanu-El in New York. The event was livestreamed.

The 62-year-old New Yorker struck a different tone from Chief Justice John Roberts, who spoke to a gathering of judges and lawyers in Colorado Springs, Colorado, last week.

“Simply because people disagree with an opinion is not a basis for questioning the legitimacy of the court,” Roberts said.

The chief justice has been a consistent defender of the court’s legitimacy against complaints that the court is not much different from the political branches of the government.

But Kagan said the court risks damaging its own legitimacy when big changes in the law follow changes in the court’s membership.

The public has a right to expect, she said, “that changes in personnel don’t send the entire legal system up for grabs.” Kagan joined the court in 2010, an appointee of President Barack Obama.

Three of the justices who are part of the court’s conservative majority were appointed by President Donald Trump. They voted to overturn Roe, and also imposed limits on the Biden administration’s efforts to fight climate change, expanded gun rights and weakened the separation between church and state.

In the court term that begins next month, the court will take up a challenge to the use of race in college admissions, just six years after the court reaffirmed affirmative action in higher education.

Kagan also briefly addressed the unprecedented leak of the draft opinion in the abortion case, saying it makes the justices’ jobs much harder “when you might wake up tomorrow morning and there’s an opinion on the front page of the newspapers.”

She said she does not know if the investigation Roberts ordered in May has determined the source of the leak.