In the United States, the answer depends on who is unlawfully in power.
In the hypothetical you presented, the answer is probably that the law would remain valid, as Congress generally has the sole authority to pass judgment on whether to admit the elected person. A third party would not have the ability to challenge the law based on the qualifications of a lawmaker.
But if we were dealing with an administrative official promulgating regulations, those rules would generally be void if that official were unlawfully appointed. That was the case in Nat'l Labor Relations Bd. v. Canning, 573 U.S. 513 (2014), where a cola distributor challenged a labor regulation, saying that the members of the NLRB who enacted it were improperly appointed. The Court agreed that the appointments were improper, so the regulations were nullified.
A judicial decision coming out under these circumstances would also be nullified if one of the judges weren't really a judge. That happened just last year, in Yovino v. Rizo. In that case, ten judges from the Ninth Circuit heard a case, and the vote split 6-4. But the author of the majority opinion died before the decision was published, which is when it become effective. The Supreme Court held that because there were therefore only five votes for that decision, it was not a majority opinion, and therefore not binding on future Ninth Circuit panels.