If someone is accused of a crime in his state and he believes the statute he is being accused of violates one or more of his constitutional rights, say right to travel or free speech. Can the defendant raise an argument in his defense, move to dismiss, or appeal the decision under these constitutional grounds? Can he open a new case as a plaintiff against the state for enforcing unconstitutional laws?
Yes, certainly. A prominent example was Lawrence v. Texas. The defendants were charged in state court with "deviate sexual intercourse". They moved to dismiss on the grounds that the statute was unconstitutional. Their motion was denied and they were convicted and fined; the denial was upheld by the state's court of appeals. They then appealed to the US Supreme Court, which eventually ruled that the statute was indeed unconstitutional.
A defendant likely wouldn't have standing to sue the state for enforcing the law in general, only for enforcing it on the defendant himself.
The defendant can challenge the constitutionality of the statute as part of a defense at trial or on appeal. As Justice Ginsburg recently explained:
Bond, like any other defendant, has a personal right not to be convicted under a constitutionally invalid law. . . .
In this case, Bond argues that the statute under which she was charged, 18 U.S.C. § 229, exceeds Congress' enumerated powers and violates the Tenth Amendment. Other defendants might assert that a law exceeds Congress' power because it violates the Ex Post Facto Clause, or the Establishment Clause, or the Due Process Clause. Whatever the claim, success on the merits would require reversal of the conviction. “An offence created by [an unconstitutional law],” the Court has held, “is not a crime.” Ex parte Siebold, 100 U.S. 371, 376 (1880). “A conviction under [such a law] is not merely erroneous, but is illegal and void, and cannot be a legal cause of imprisonment.” Id., at 376-377. If a law is invalid as applied to the criminal defendant's conduct, the defendant is entitled to go free.
For this reason, a court has no “prudential” license to decline to consider whether the statute under which the defendant has been charged lacks constitutional application to her conduct. And that is so even where the constitutional provision that would render the conviction void is directed at protecting a party not before the Court. Our decisions concerning criminal laws infected with discrimination are illustrative. The Court must entertain the objection--and reverse the conviction--even if the right to equal treatment resides in someone other than the defendant. See Eisenstadt v. Baird, 405 U.S. 438, 452-455 (1972) (reversing conviction for distributing contraceptives because the law banning distribution violated the recipient's right to equal protection); cf. Craig v. Boren, 429 U.S. 190, 192 (1976) (law penalizing sale of beer to males but not females aged 18 to 20 could not be enforced against vendor). See also Grayned v. City of Rockford, 408 U.S. 104, 107, n.2 (1972); Welsh v. United States, 398 U.S. 333, 361-362 (1970) (Harlan, J., concurring in result) (reversal required even if, going forward, Congress would cure the unequal treatment by extending rather than invalidating the criminal proscription).
In short, a law “beyond the power of Congress,” for any reason, is “no law at all.” Nigro v. United States, 276 U.S. 332, 341 (1928). The validity of Bond's conviction depends upon whether the Constitution permits Congress to enact § 229. Her claim that it does not must be considered and decided on the merits.
Bond v. United States, 564 U.S. 211, 226-28 (2011) (Ginsburg, J., concurring).
Rules must not conflict with statutes, however, or impair the legal rights of the parties.2 Thus a court has no power to declare a rule what shall constitute a waiver of a constitutional right.3 And the code provides that rules made by a court "shall neither impose any tax, charge, or penalty upon any legal proceeding, or for filing any pleading allowed by law, nor give any allowance to any officer for services."4 7Cal.Jur.§35
That is not an allowed argument, so would be quashed by the judge. That does not mean that a defendant defending himself could not blurt out some such rant, but only the judge is allowed to address the matter of what the law is, and any such rant would be stricken from the record and the jury would be instructed to disregard the rant. And, of course, all laws are assumed to be constitutional. A motion to dismiss would almost certainly be denied (if the basis was the claim that the law is unconstitutional), but if the law were in fact unconstitutional, that motion (and dismissal) would be a foot in the doorway for having the law overturned on appeal.
Another way to get a law overturned is to sue the government in advance of being arrested, because you were harmed (prevented from exercising your rights). Heller is an example, where plaintiffs were harmed by infringement of their 2nd Amendment rights. This is somewhat different though from being convicted of a crime.
The determination that a law is unconstitutional is not decided in trial court.