In a lot of places in the Western World it all comes down to whether or not "you're a danger to yourself and others", and some places extend that to mean using alcohol and drugs in a dangerous way, or even simply "not taking care of your basic needs".
It can be initiated in a few different ways. If a police officer or certain health-care workers or a court feels that you're acting in a "dangerous" way, they can usually have you "evaluated"....If you end up in the psych ward on an evaluation, you're interviewed and observed for a period of time...Usually, if you're calm and answering the questions in a clear, rational way, the doctor in charge of your case will cut you lose after only a couple of hours. If you're on drugs or acting like a weirdo in any way, you'll usually be held for 3-5 days for further observation. If in that time it's determined that you're okay, you'll be let go. If the doctor feels that you need to be held and treated for a longer period, you'll be given a court date to determine whether or not should be involuntarily committed and held until the court-date.
^This is actually very similar to being arraigned for a crime. You're allowed to have a lawyer defend you and present your side of the case and whoever is trying to have you committed is allowed to present evidence showing why you should be held. If it's determined that you should be held further, you're sent back to the psych-ward and given another court date about a month or so from then where the same thing happens, so it's essentially like a 30 day prison sentence!...You can also be forcibly medicated if you're involuntarily committed, which is the most evil thing of all IMO! Also, when you do get out, guess who has to pay thousands of dollars for the hospital stay?! In the US, the person held against their will is financially responsible!
Unless you are truly going "Bat Shit Crazy", you'll generally get out within a few days unless you're sent there because of a petition signed by your family or associates. For some reason, when it's your family trying to have you committed, it seems to carry a lot more weight than anything else, and if it's proven that you have a history of drug use and "mental illness", even if it's just depression and suicidal ideation, you'll usually end up in there for awhile until you can somehow convince them that you're okay!
It's a really fucked up law that I think a lot of people assume could never be used against them as long as they're not running naked down the street screaming, but it's a lot easier than you make think!
Having people involuntarily held because of drug abuse is controversial and definitely a "grey area" in the law that's interpreted differently in different cases and locales, but if it's your family or SO signing a petition against you, it's "crazy until proven sane"! Pretty fucked up....