He was in private practice in Houston, Texas, from 1979 to 2002. In 1992, Hanen was nominated by President George H. W. Bush to be a United States District Judge, but the nomination lapsed.
During sentencing of a convicted child smuggler in December 2013, Hanen sharply rebuked the United States Department of Homeland Security for not prosecuting the child's mother. Hanen wrote, "DHS should cease telling the citizens of the United States that it is enforcing our border security laws because it is not. Even worse, it is helping those who violate these laws." While on the bench, Hanen "developed a reputation as an outspoken judicial critic of the Obama administration's immigration policies". In February 2015, Hanen granted the State of Texas's motion for a nationwide preliminary injunction barring President Barack Obama from carrying out the Deferred Action for Parents of Americans program. In United States v. Texas, that ruling was affirmed by an equally divided Supreme Court of the United States on June 23, 2016. On May 19, 2016, while the case was awaiting decision at the Supreme Court, as a lesser alternative to entirely striking the government's pleadings, Hanen demanded that some 3,000 Department of Justice lawyers in 26 states take ethics classes, and ordered other sanctions for those who argued Texas v. United States, involving President Obama's immigration executive actions. Hanen did not explain why he extended his sanctions to attorneys who had no involvement in the case. Hanen accused Justice Department's lawyers of lying to him during arguments in the case, and barred them from appearing in his courtroom. He accused the department of "a calculated plan of unethical conduct". Hanen also ordered Attorney GeneralLoretta Lynch to appoint someone within the department to ensure compliance with his order. Hanen also ordered U.S. immigration officials to turn over, within weeks, the names and addresses of 50,000 people who received deferral under the expanded deferred-action initiative. The National Immigration Law Center, the American Civil Liberties Union Immigrants' Rights Project, and the ACLU of Texas petitioned the United States Court of Appeals for the Fifth Circuit to vacate the order or postpone the deadline. Separately, the Justice Department argued in a filing in the district court than Hanen's ordered sanctions "exceed the scope of authority and unjustifiably impose irreparable injury on the Department of Justice, the Department of Homeland Security and thousands of innocent third parties." The Justice Department also argued that additional ethics courses could cost up to $7.8 million over five years. On June 7, 2016, Hanen stayed his order requiring ethics courses for federal attorneys and requiring U.S. immigration officials to turn over the names and addresses until August 2016.