You're certainly referring to "Ex Post Facto" laws, and while the US is constitutionally prohibited from passing criminal laws that are retroactive, the US Supreme Court has upheld many tax laws that apply tax code changes retroactively.
You might ask a similar question on Law.SE for a more thorough treatment of the legalities of congress passing those laws, but I will stick to the personal finance portion of the question.
What this means is that you can't expect that the current tax laws will be in force in the future, and your investment/retirement plans should be as flexible as possible. You may wish to have some money in both Roth and traditional 401(k) accounts. You might not want to have millions of dollars in Roth accounts, because if congress does act to limit the tax benefits of those accounts, it will probably be targeting the larger balances.
If you are valuing tax deductions, you should put slightly more weight on deductions that you can take today than deductions that would apply in the future.
If you do find yourself in trouble because of a retroactive change, be sure to consult a tax lawyer that specializes in dealing with the IRS to possibly negotiate a settlement for a lower amount than the full tax bill that results from the changes.