A U.S. federal judge on Tuesday ordered a controversial Arizona sheriff to undergo the same training as his deputies to prevent racial profiling and unlawful detention in the wake of the lawman's recent comments.

U.S. District Court Judge Murray Snow criticized sheriff Joe Arpaio during a hearing in Phoenix for telling a reporter he would have no problem conducting an immigration sweep like one performed in the town of Guadalupe in 2008, which was later declared unconstitutional.

The judge ruled in May 2013 that Arpaio, who bills himself as "America's Toughest Sheriff," violated the rights of Latino drivers with his crackdown on illegal immigration and ordered him to stop using race as a factor in law enforcement decisions.

Snow said Arpaio's recent comments undermined his office's efforts to comply with the ruling.

The ruling stems from a 2007 class-action lawsuit by Hispanic drivers, who argued they were unlawfully singled out for traffic stops on the basis of ethnicity.

The case tested whether police could target unauthorized illegal immigrants without racially profiling U.S. citizens and legal residents of Hispanic origin.

Arpaio's operation in Guadalupe were a major part of the case.

Arpaio did not attend Tuesday's hearing, but has consistently denied allegations of racial profiling and is appealing the judge's ruling.

His attorney, Tim Casey, argued that Arpaio's recent statements were protected by the First Amendment and questioned whether they would impact the office's improvement efforts.

"Good faith exists in the deed, not the spoken word," he told the court.

Plaintiff’s attorney and director of the American Civil Liberties Union Immigrants' Rights Project, Cecillia Wang, said Arpaio should be held in contempt if his behavior continues.

"He needs to know that there will be consequences for his actions," Wang said after the hearing.

The judge also criticized the office's handling of an investigation into allegations that a deputy who committed suicide was shaking down illegal immigrants and that others may have been involved.

Ramon "Charley" Armendariz, who testified at the racial profiling trial, was found with numerous videotapes of traffic stops and personal information of drivers with Hispanic surnames at his home. Included were license plates, credit cards and identification cards.

A monitor appointed by the court to watch Arpaio’s operations said on Tuesday the investigation by sheriff’s officials was sorely lacking.

(Editing by Curtis Skinner and Michael Perry)