The essence of the American criminal justice system is reactive, not predictive: You are punished for the crime you committed. You can’t be punished simply because you might commit one someday. You certainly can’t be held indefinitely to prevent that possibility.

And yet that is exactly what is happening to about 5,000 people convicted of sex crimes around the country. This population, which nearly doubled in the last decade, has completed prison sentences but remains held in what is deceptively called civil commitment — the practice of keeping someone locked up in an institution for months, years or even decades for the purpose of preventing possible future offenses.

The authorities have the power to detain people with mental illnesses or disorders who cannot function independently, or who pose a danger to themselves or others. But since the early 1990s, this power has been used increasingly to imprison one distinct group: sex offenders.

Federal law and the laws in 20 states and the District of Columbia allow people convicted of violent sex crimes — such as rape or child molestation — to be held in custody indefinitely past the end of their criminal sentences. The Supreme Court has upheld these laws on the grounds that they are not intended to punish or deter crime, but only to hold people until they are no longer a threat. In theory, a civilly committed person gets treatment and is released as soon as possible.