The justice, appointed to the court by President Barack Obama in 2009, took the relatively unusual step of writing a statement to accompany the nine-member Supreme Court's announcement that it would not take up a criminal case.
Sotomayor took issue with the question asked by the prosecutor, identified in the trial transcript as Assistant U.S. Attorney Sam Ponder.
While questioning an African-American defendant in a drug case, Ponder asked: "You've got African-Americans, you've got Hispanics, you've got a bag full of money. Does that tell you - a light bulb doesn't go off in your head and say, this is a drug deal?"
The first Hispanic Supreme Court justice, Sotomayor wrote that the prosecutor had "tapped a deep and sorry vein of racial prejudice that has run through the history of criminal justice in our nation."
The question was "pernicious in its attempt to substitute racial stereotype for evidence," she added. Sotomayor also accused the Obama administration of playing down the issue.
The defendant in the case, Bongani Charles Calhoun, wanted the Supreme Court to order a retrial because he said his right to a fair trial was violated when the question was asked. He was convicted of three offenses over his role in a drug conspiracy.
Initially, the administration declined to file a response to Calhoun's claim, indicating government lawyers did not think it merited attention.
"I hope never to see a case like this again," Sotomayor wrote.
Justice Stephen Breyer signed on to Sotomayor's statement.
Reached by telephone on Monday, Ponder declined to comment.
A spokesman for the U.S. Attorney's Office for the Western District of Texas, where Ponder is listed as working, said the matter had been referred to the U.S. Department of Justice's Office of Professional Responsibility, which handles allegations of attorney misconduct. He declined to comment further.
Tom Moran, the Houston-based lawyer who filed Calhoun's Supreme Court petition, said Sotomayor's statement should be taken to heart by other prosecutors.
Moran said Ponder "got slapped around pretty good" by the justice.
The Supreme Court did not take up the case on Monday, because Calhoun had failed to raise his argument earlier in the appeals process, as required under the law, Sotomayor wrote.
At trial, Calhoun's argument was that although he was present when federal agents arrested him and several other men, he was unaware of the illegal activity.
The case is Calhoun v. United States, U.S. Supreme Court, 12-6142.
(Reporting by Lawrence Hurley; Editing by Howard Goller and Mohammad Zargham)