At the time the constitution was adopted this was how it was defined. An ex post facto law is any law that changes a person's legal standing or obligations to their disadvantage after the fact.
That means anything, not just criminal law. The obligations part was due to indentured servitude and slavery.
The supreme court has since eroded this protection, and narrowed the meaning to limit it to specific, narrowly defined forms of court imposed criminal punishment. A retroactive law in Kansas, upheld by the supreme court, allowed a sex offender to be incarcerated indefinitely, without right to trial, to face his accusers, have counsel for his defense, call witnesses for his defense, have a jury or speak on his own behalf. Because it was a civil law, he wasn't facing "punishment," reasoned the supreme court, the ex post facto prohibition as well as the 4th, 5th, 6th and 8th amendments did not apply.
The supreme court ruled that involuntary incarceration, a universally recognized and previously indisputable form of punishment, was not punishment. As long as you call it civil law, it is exempt from all constitutional restrictions. Call it civil and the accused is stripped of all rights. The precedent is appalling!
Please note: the defendent in this case faced no criminal charges. He had served 100% of his sentence for crimes previously committed and, by law and thousands of years of legal precedents, had earned his release. Instead He was sentenced to be indefinitely incarcerated because of something he might do in the future. If you feel this is a good idea, consider this:
This is why we require trials. That man was facing life in prison for a rape he didn't commit! He spent nearly 30 years in prison. Under the supreme court ruling, he could have been in another 30, with no recourse.