Well...in Germany, involuntary psychiatric commitment, usually called as a "mental hold" or compulsory hospitalization, starts up when an individual's mental health is deemed to impair their sanity to the point of posing a danger to themselves or others, or in certain criminal contexts.
Note....there IS NOT a single national mental health law but instead involves a combination of federal codes and state-specific regulations (remember 16 states).
So in effect....you could be signed off to a clinic in one state for obvious issues....but if you were in Hamburg, or Bavaria....you might not be dragged off.
I'll add here.....there's always a judge involved, and some court appointed person to report on things.....and to protect your civil rights.
The three key points? You have to show some threat/danger to self or others. You probably will show some or total capacity to control yourself, or consent to things. Finally, there might be some criminal element....influenced by a mental disorder, where preventive detention may make sense.
Exiting? There will always be a scripted 'end' where you can test your way out, or have a judge review your success of resolving your issue.
I looked up the numbers....out of 84-M folks....around 1-milllion are in some 'program' (some voluntary....some ordered). Based on 2023 numbers.....around 25-percent of the million are NON-volunteers....meaning the judge restricted them to a program (for a short or long period of time).
Based on the way they count issues.....most are there for a week or two....to stabilize themselves....because nationally, there are only 65,000 beds dedicated to such units.
The way to look at this....you get doped-up and act crazy....police come and you end up in a holding-cell....where the judge has you sent to a 10-day mental clinic....where some doctor will note you were just temporarily crazy...signs the papers, and out you go by the 10th day. In and out....would be the best way to describe this.
The plus-side of this program? Well....you don't end up in a prison (like in the US) for 4 years...for stupid crap. The German method just notes you needed treatment and the threat of being hospitalized....to correct your behavior.