Psychiatric doctrine asserts entitlement to incarcerate someone on grounds of the bogeymen of suicidal and homicidal ideations. This is arguably a bit rich, because suicide and homicide are both criminally illegal so here psychiatric industry is arguably sidestepping criminal due process rights. But to dig into a bit more detail while committing suicide and committing homicide are both crimes, and threatening homicide is almost certainly a crime in majority if not all jurisdictions, what about merely threatening suicide without following through?
suicide and homicide are both criminally illegal
This is incorrect: according to the LII article "Suicide" :
Suicide is no longer considered a crime in the United States; however, some states have attempted suicide listed as a crime in their criminal statutes. On the other hand, assisted suicide (when someone helps another to commit suicide) is a crime in all U.S. states, with physician-assisted suicide being an exception to this rule in some states.
The Wikipedia article "Suicide legislation" confirms this.
detention and involuntary commitment for treatment of those thought likely to commit suicide is not based on criminality, and is not supposed to be a punishment. Rather it is based on preventing them from harming their own best interests. At least, that is the legal theory. And such persons do have due process rights, and can bring an action. In the case of O'Connor v. Donaldson, 422 U.S. 563 (1975) the US Supreme Court majority opinion stated:
A finding of "mental illness" alone cannot justify a State's locking a person up against his will and keeping him indefinitely in simple custodial confinement. Assuming that that term can be given a reasonably precise content and that the "mentally ill" can be identified with reasonable accuracy, there is still no constitutional basis for confining such persons involuntarily if they are dangerous to no one and can live safely in freedom.
The court in that case specifically declined to decide whether a state might confine a person adjudges dangerous to himself.