In 1946, the Supreme Court struck down a law that named three people as subversive and banned them from federal jobs. The Constitution bans bills of attainder—laws that target individuals or groups for punishment without a trial.
The test is whether a law applies to specific people and imposes punishment. The Court said in United States v. Lovett that Congress can't name someone dangerous and exclude them from work—that's the job of courts, not legislatures. In 1965, the Court struck down a law making it a crime for Communist Party members to serve as union officers, calling it punishment without trial. But when Congress forced Richard Nixon to hand over his presidential papers after Watergate, the Court said that wasn't a bill of attainder because it served other government purposes beyond punishment. The ban prevents Congress from acting as prosecutor, judge, and jury.