The only comforting narrowness is that it is only for Federal Prisoners that are already in custody. .... But yup, terrifying legal concept that was just sanctioned by our highest court.
I'm not sure I agree even it's comforting at even that point, because if this law was passed after those people were incarcerated it would seem to violate Ex Post Facto. And yes, this is indeed terrifying. Adding to a person's sentence after they have already served it, deciding that they "need to stay locked up," is arbitrary and capricious. Where is the due process here? This seems to be another case of emotionally induced blindness to the equally applied rule of law.
Locking them up in a mental institution immediately after their prison term ends is no better. Why? It implies they are subject to an illness beyond their control, hence why were they sent to prison instead in the first place? If true, they should have been in the mental institution from the start for treatment of their mental illness. Being found mentally competent and guilty for one's actions in a criminal court, sentenced, and then after having served out that sentence being confined against one's will to a mental institution is nothing more than unlawful detention under the guise of medical practice "for the public good."
For an exercise try going back and reading that again, except this time replace "sex offender" with say, "thief," "violent offender," or my personal favorite, "political dissident."