The president’s outburst appeared to be inspired by a Fox News segment from host Laura Ingraham which said Justice Sotomayor had accused Republican-appointed justices of being “biased in favour of Trump”.
“This is a terrible thing to say. Trying to ‘shame’ some into voting her way? She never criticised Justice Ginsberg [sic] when she called me a ‘faker,’” Mr Trump wrote, referring to a comment by Ms Ginsburg from 2016.
“Both should recuse themselves on all Trump, or Trump related, matters! While ‘elections have consequences’, I only ask for fairness, especially when it comes to decisions made by the United States Supreme Court!”
In 2016, Justice Ginsburg called Mr Trump a "faker" who has "no consistency about him" and said she could not imagine him as the president.
Although she did not heed Mr Trump's call for her to resign, she did express regret over the comment, which she said was "ill-advised".
Justice Sotomayor, who is one of four liberal-minded justices on the court, wrote a scathing dissent on Friday which criticised her conservative colleagues for being too eager to side with the Trump administration on emergency requests to the court.
“Claiming one emergency after another, the government has recently sought stays in an unprecedented number of cases,” Justice Sotomayor wrote.
“It is hard to say what is more troubling; that the government would seek this extraordinary relief seemingly as a matter of course, or that the court would grant it.”
The Trump administration has used emergency requests to the Supreme Court to force through controversial policies, such as the so-called "public charge" rule which would make it more difficult for immigrants to obtain legal status if they use public benefits like food stamps.
“I cannot do my job here at the department with a constant background commentary that undercuts me,” Mr Barr told ABC News.
The president’s attack on Justices Ginsburg and Sotomayor drew anger on social media, with some commentators accusing him of acting like a dictator.
“He’s corrupted the Senate, Justice Dept and DNI/intelligence and now he’s going after the Supreme Court,” Andy Ostroy, a Democrat-supporting political commentator, wrote on Twitter.
“Wake up America, he’s creating a dictatorship.”
Brian Fallon, the executive director of Demand Justice, a liberal judicial advocacy group, said Mr Trump was attacking Justice Sotomayor for “speaking the truth”, while political commentator David Frum warned that more attacks from the president were likely.
“As Supreme Court moves closer to deciding the Trump business document cases before June, we will likely hear more of these attacks on the non-Trump-appointed justices both from Trump himself and from pro-Trump media,” Mr Frum said.
“Sotomayor complains that the Supreme Court shows undue deference to the federal government requests for stays of injunctions,” he added.
“Trump interprets these comments about undue deference to the government as ‘bias in favour of Trump’ - because in his mind, ‘the government’ = HIM.”
The president’s outburst also came one day after it was reported that a group of pro-Trump activists including Ginni Thomas, the wife of Justice Clarence Thomas, had compiled lists of “disloyal” government officials.
US media reports have claimed Ms Thomas gave suggestions to the White House about which officials should be fired for not supporting Mr Trump’s administration.
The White House has not yet responded to a request for comment on the allegations.