In such a case there could, in the united-states, be a defense of selective prosecution. To establish this the defendant would need to show that others had actually committed the same offense in similar circumstances, but were not prosecuted, and that further the prosecutor had acted from arbitrary and impermissible motives in deciding which cases to prosecute.
Most of the invocations of the rule against selective prosecution have alleged racial bias on the part of the police and/or the prosecutors, and even so most of the claims of selective prosecution have failed.
However, evidence that accused with certain political views were prosecuted, while those with other, more favored views were not, when the offenses and circumstances were similar might amount to a defense of selective prosecution.
In "What About Selective Prosecution" from Fordham Law News a case of allegedly political selective prosecution is discussed, the case of Kathleen Kane, then Attorney General of Pennsylvania. There had been no court ruling on the claims of selective prosecution when the article was published.
The caselaw I have found all agrees that selective prosecution is a hard but not impossible defense to establish. The defendant at trial must provide clear evidence that others similarly situates are not prosecuted, and of an improper motive on the part of the prosecutor. This burden was sustained in Yick Wo v. Hopkins, 118 U. S. 356, 373 (1886) but such a defense was rejected in many other cases.
A relatively recent case in the US Supreme Court dealing with alleged selective prosecution was United States v. Armstrong, 517 U.S. 456 (1996) In that case it was alleged prosecutions for crack cocaine dealing along with firearms possession were brought almost solely against black defendants and not against those of other races. The defendants sought discovery of all cases dealing with such offense patterns brought by the US DoJ in the previous three years, along with the races of all such defendants, in an effort to demonstrate such a pattern of bias. The Court ruled that defendants must make at least some showing that there had been others similarly situated who were not prosecuted before they were entitled to such broad discovery.
In the opinion in Armstrong Chief Justice Rehnquist wrote:
Of course, a prosecutor's discretion is "subject to constitutional constraints." United States v. Batchelder, 442 U. S. 114, 125 (1979). One of these constraints, imposed by the equal protection component of the Due Process Clause of the Fifth Amendment, Bolling v. Sharpe, 347 U. S. 497, 500 (1954), is that the decision whether to prosecute may not be based on "an unjustifiable standard such as race, religion, or other arbitrary classification," Oyler v. Boles, 368 U. S. 448, 456 (1962). A defendant may demonstrate that the administration of a criminal law is "directed so exclusively against a particular class of persons ... with a mind so unequal and oppressive" that the system of prosecution amounts to "a practical denial" of equal protection of the law. Yick Wo v. Hopkins, 118 U. S. 356, 373 (1886).
In order to dispel the presumption that a prosecutor has not violated equal protection, a criminal defendant must present "clear evidence to the contrary." Chemical Foundation, supra, at 14-15. We explained in Wayte why courts are "properly hesitant to examine the decision whether to prosecute." 470 U. S., at 608. Judicial deference to the decisions of these executive officers rests in part on an assessment of the relative competence of prosecutors and courts. "Such factors as the strength of the case, the prosecution's general deterrence value, the Government's enforcement priorities, and the case's relationship to the Government's overall enforcement plan are not readily susceptible to the kind of analysis the courts are competent to undertake." Id., at 607. It also stems from a concern not to unnecessarily impair the performance of a core executive constitutional function. "Examining the basis of a prosecution delays the criminal proceeding, threatens to chill law enforcement by subjecting the prosecutor's motives and decisionmaking to outside inquiry, and may undermine prosecutorial effectiveness by revealing the Government's enforcement policy." Ibid.
The requirements for a selective-prosecution claim draw on "ordinary equal protection standards." Id., at 608. The claimant must demonstrate that the federal prosecutorial policy "had a discriminatory effect and that it was motivated by a discriminatory purpose." Ibid.; accord, Oyler, supra, at 456. To establish a discriminatory effect in a race case, the claimant must show that similarly situated individuals of a different race were not prosecuted. This requirement has been established in our case law since Ah Sin v. Wittman, 198 U. S. 500 (1905). Ah Sin, a subject of China, petitioned a California state court for a writ of habeas corpus, seeking discharge from imprisonment under a San Francisco County ordinance prohibiting persons from setting up gambling tables in rooms barricaded to stop police from entering. Id., at 503. He alleged in his habeas petition "that the ordinance is enforced 'solely and exclusively against persons of the Chinese race and not otherwise.''' Id., at 507. We rejected his contention that this averment made out a claim under the Equal Protection Clause, because it did not allege "that the conditions and practices to which the ordinance was directed did not exist exclusively among the Chinese, or that there were other offenders against the ordinance than the Chinese as to whom it was not enforced." Id., at 507-508.