Is there any legal basis or precedent to detain someone for the
purpose of preventing the mere possibility of unspecified crimes that
might be committed?
Short answer: Yes.
There are several circumstances in which someone can be detained because they might commit future crimes, although the Homeland Security case you identify does not fit that description.
Detention Prior To Deportation Or Prior To A Criminal Trial
The primary purpose of pretrial detention prior to a deportation is essentially the same as pretrial detention prior to a criminal case that could result in incarceration: to avoid having to go out and arrest the person all over again for the violation of law (civil or criminal as the case may be) of which they are accused.
In each case, the question that justifies pre-due-process detention is whether there is probable cause that a law authorizing detention has been violated.
The fact that unspecified future crimes that might have been committed by that person may be prevented is merely an added bonus that goes into the cost-benefit calculation of whether it is a good idea to detain someone, and into analyzing the terms of pretrial detention that make sense.
Other Forms Of Preventative Detention
But, there are a variety of circumstances when people can be detained purely for unspecified future crimes.
Preventative Mental Health Detention
One is a mental health hold, typically for 72 or 96 hours initially, subject to being made permanent. To impose a temporary mental health hold one must typically show probable cause to believe that the person is a threat to themselves or others, and must meet a higher standard of proof over a longer period of time to show a danger to themselves or others for a more permanent involuntary commitment to a mental institution.
One subset of this kind of detention is for persons found innocent of a crime by reason of insanity, but mental health detention is authorized even in the absence of such circumstances.
Involuntary Physical Health Detention
Often, a hospital is authorized to detain someone to protect their physical health until they are stabilized, even against their will. While the primary focus is often the threat posed to the patient, preventing future crimes such as vehicular homicide by an infirm person trying to drive themselves home is also a consideration.
Similarly, many jurisdictions allow for civil commitment in a "drunk tank" until someone is sober, without further criminal charges or legal process, in order to prevent crimes such as drunk driving, assaults, rapes, and disorderly conduct.
Protective Custody
Protective custody is the detention of someone in imminent danger of being a victim of a violent crime if not detained. This is most often applied in the case of people who are currently incarcerated and at risk of harm from other prisoners.
But, a paradigmatic example of protective custody outside the jail or prison context is the protective custody of an individual who is at imminent risk of being lynched despite the fact that authorities believe that the person is not guilty of a crime, in order to prevent that person from being harmed.
Protective custody is also often ordered for children when there is a well founded fear that they are at risk of ongoing or imminent abuse or neglect.
The homeless are sometimes detained as a matter of policy for offenses that would ordinarily not be enforced or for marginal medical reasons, primarily as a matter of protective custody, when there is a fear that the individuals will suffer serious injury from exposure or from circumstances that make them particularly likely to be victims (e.g. following a surge of vigilante killings of homeless people).
Parole Release Decisions
Another one is a parole determination. Once you have been convicted of a crime and served a certain minimum sentence, the question of whether you will be required to continue to serve a prison sentence is often decided by a parole board on the basis of whether you are likely to commit an unspecified future crime.
Preventative Detention Of Sex Offenders
A third one relates to sex offenders. If an evaluation by a board determines that you are likely to commit new unspecified sex crimes if released, you can be detained indefinitely until the board determines that you are no longer a threat.
Technical Violations Of Probation Or Parole
A fourth one relates to people on probation following a conviction, or who have been released on parole. In those situations actions which would otherwise be legal can be criminalized on the grounds that they demonstrate a likelihood of committing future unspecified crimes and can result in reincarceration for a period of time.
Unsupervised Minors And Curfew Violations By Minors
A fifth one related to unsupervised minors, either out after curfew or simply without a parent or guardian in general (such as a runaway). Part of the justification for allowing minors in these cases to be incarcerated is that they will commit an unspecified future crime.
Emergencies
Adult curfew violations can also fit in this category. Usually, these are imposed only during emergencies, in part, to prevent crimes. People can also be detained for failing to comply with a mandatory evacuation order, partially for that person's own protection, but also partially to prevent the potential of future looting.
A more extreme example is the lockdown of greater Boston following the Boston Marathon bombing, to prevent future unspecified crimes by the bomber, the legal validity of which, so far as I know, was never tested.
Quarantines
While not precisely a crime, people can also be detained pursuant to a quarantine because there is a likelihood that they will pass a disease to an unspecified future person – effectively assaulting or killing them – if not detained.
Detention of Enemies In Times Of War
Yet another relates to enemy non-combatants. A country that is at war with another country is permitted under international law to detain nationals of the country that they are at war with, without any individualized suspicion, out of fear that they will commit unspecified acts of war against the detaining country, which would also amount to crimes. The same justification authorizes detention of enemy combatants as prisoners of war (but subject to more harsh conditions than non-combatants).
Criminalization Of Conduct Likely To Lead To Crimes
Of course, there are a variety of crimes that exist to prevent other crimes in the future and not really because the crime itself is harmful. These include possession of a firearm by a felon, possession of burglary tools or drug paraphernalia, driving with an open container of alcohol, violation of a restraining order, possession of explosives without a license, buying scrap metal or pawn items (or selling Sudafed) without recording the other party's identifying information, providing material assistance to terrorism, selling firearms to someone in violation of regulations, and making various kinds of credible threats (although these are usually pertaining to someone specified crimes). Disorderly conduct and public drunkenness are often used in this manner as well.
Guilt By Association
Membership in a criminal street gang as that is legally defined, for example, in Texas, under certain circumstances can be a crime, even if you do not personally engage in an act that would be criminal were you not a member of that gang (for example, being present in a "gang free zone").
Membership in a criminal gang can also be a penalty enhancer under 18 U.S.C. § 521, although it is not a primary offense under federal law.
Federal law does make it a crime and authorize indefinite detention or death under military discretion, for being a member of certain terrorist organizations identified in the Authorization for Use of Military Force (AUMF) since the United States has declared war on those organizations.
Non-Criminal Short Term Discretionary Detention
Indeed, some center-left proponents of reducing mass incarceration have actually proposed that police be given the authority to detain people primarily because they fear that a crime will occur if they do not do so, for short periods of time (perhaps an hour to eight hours) called a field detention, without creating any public record of the detention, or collateral consequences, with only limited monetary recourse for abuses of this power.
They have proposed this because police officers, in practice, can get away with doing this anyway in a wide variety of circumstances with greater consequences for the person detained. In some countries, police basically do have this power.
The notion is, for example, to remove someone from a situation when a situation between two people or two groups of people is escalating into a fight, before a fight actually breaks out.
Conclusion
In general, legislatures have quite broad authority to criminalize conduct that is believed to involve a likelihood that some other crime will be committed, and there are many circumstances, some of which may not yet be recognized in any law, where the legislature could constitutionally authorize detaining someone because they might commit a crime, or because someone might otherwise victimize them.
But, this authority can be limited, not only politically, but because it infringes some other right, such as freedom of religion or freedom of association, in a manner that is not strictly tailored to a compelling state interest.