Article 1 Section 9 of the US Constitution forbids ex post facto laws, as do most state Constitutions.
No Bill of attainder or ex post facto Law shall be passed.
Article 1 Section 10 of the US Constitution also forbids States from passing ex post facto laws.
No State shall enter into any Treaty, Alliance, or Confederation; grant Letters of Marque and Reprisal; coin Money; emit Bills of Credit; make any Thing but gold and silver Coin a Tender in Payment of Debts; pass any Bill of Attainder, ex post facto Law, or Law impairing the Obligation of Contracts, or grant any Title of Nobility.
In a letter to Isaac McPherson, dated August 13, 1813, Thomas Jefferson wrote this about the matter.
The sentiment that ex post facto laws are against natural right is so strong in the United States, that few, if any, of the State constitutions have failed to proscribe them. The federal constitution indeed interdicts them in criminal cases only; but they are equally unjust in civil as in criminal cases, and the omission of a caution which would have been right, does not justify the doing what is wrong. Nor ought it to be presumed that the legislature meant to use a phrase in an unjustifiable sense, if by rules of construction it can be ever strained to what is just.
In Federalist No. 44, James Madison wrote a defense for the outlawing of bills of attainder and ex post facto laws.
Bills of attainder, ex-post-facto laws, and laws impairing the obligation of contracts, are contrary to the first principles of the social compact, and to every principle of sound legislation. The two former are expressly prohibited by the declarations prefixed to some of the State constitutions, and all of them are prohibited by the spirit and scope of these fundamental charters. Our own experience has taught us, nevertheless, that additional fences against these dangers ought not to be omitted. Very properly, therefore, have the convention added this constitutional bulwark in favor of personal security and private rights; and I am much deceived if they have not, in so doing, as faithfully consulted the genuine sentiments as the undoubted interests of their constituents. The sober people of America are weary of the fluctuating policy which has directed the public councils. They have seen with regret and indignation that sudden changes and legislative interferences, in cases affecting personal rights, become jobs in the hands of enterprising and influential speculators, and snares to the more-industrious and less-informed part of the community. They have seen, too, that one legislative interference is but the first link of a long chain of repetitions, every subsequent interference being naturally produced by the effects of the preceding. They very rightly infer, therefore, that some thorough reform is wanting, which will banish speculations on public measures, inspire a general prudence and industry, and give a regular course to the business of society.
. . .
The establishment of the writ of habeas corpus, the prohibition of ex-post-facto laws, and of TITLES OF NOBILITY, TO WHICH WE HAVE NO CORRESPONDING PROVISION IN OUR CONSTITUTION, are perhaps greater securities to liberty and republicanism than any it contains. The creation of crimes after the commission of the fact, or, in other words, the subjecting of men to punishment for things which, when they were done, were breaches of no law, and the practice of arbitrary imprisonments, have been, in all ages, the favorite and most formidable instruments of tyranny. The observations of the judicious Blackstone, in reference to the latter, are well worthy of recital: "To bereave a man of life, Usays he,e or by violence to confiscate his estate, without accusation or trial, would be so gross and notorious an act of despotism, as must at once convey the alarm of tyranny throughout the whole nation; but confinement of the person, by secretly hurrying him to jail, where his sufferings are unknown or forgotten, is a less public, a less striking, and therefore A MORE DANGEROUS ENGINE of arbitrary government." And as a remedy for this fatal evil he is everywhere peculiarly emphatical in his encomiums on the habeas-corpus act, which in one place he calls "the BULWARK of the British Constitution."
Basically, Madison justifies the proscription of ex-post-facto laws as necessary for upholding the social contract between the government and its people and staving off tyranny. Ultimately, much of the US Constitution was written with the prevention of tyranny in mind, and ex post facto laws were considered an "instrument of tyranny."
In regards to lex mitior, an early Supreme Court case seems to uphold it. Calder v. Bull, 3 U.S. (3 Dall.) 386 (1798) found that the ex post facto clause in the Constitution applies to criminal law with at least one of these four effects.
- Every law that makes an action done before the passing of the law, and which was innocent when done, criminal; and punishes such action.
- Every law that aggravates a crime, makes it greater than it was, when committed.
- Every law that changes the punishment, and inflicts a greater punishment, than the law annexed to the crime, when committed.
- Every law that alters the legal rules of evidence, and receives less, or different, testimony, than the law required at the time of the commission of the offence, in order to convict the offender.
So, under US case law, although the Constitution prohibits ex post facto laws specifically, the courts have held to the standard of a less strict form of lex mitior in general. However, this is only in regards to whether or not a law can legislate against prior behavior. It has no standing in regards to whether or not a change of law should necessarily be applied to past behavior.
For instance, in New Mexico, the death penalty was abolished in 2009, but people who committed capital offenses prior to this change in law could still be subject to the death penalty. This is because the law was specifically not retroactive. If the Constitution mandated lex mitior, I believe that the abolition of the death penalty would necessarily be required to apply retroactively whereas under the US interpretation of the prohibition of ex post facto laws, it would merely be legal for New Mexico to have crafted the legislation so that it applied retroactively.
So, ultimately, the prohibition of such laws is grounded in our Constitution. The Courts have interpreted this prohibition under a lex-mitior-lite interpretation wherein it is merely legal for legislation to make punishments for prior actions less severe rather than necessary to interpret legislation in that manner. As for what this means in the current context and how it has developed into the present, Fizz's answer is sufficient. I merely wanted to point out that the reason that ex post facto laws are prohibited in American jurisdictions is because our founding document, the US Constitution, particularly demands it, and that this provision was justified by those who wrote the Constitution.