The term 5150 stems from the California welfare and institutions code that gives medical professionals the power to hold a patient for up to 72 hours.
A 5150 code is used when:
you're a danger to yourself or others
you're unable to take care of yourself (unable to provide food, clothing, or shelter)
the danger or inability to take care of yourself is the result of a mental illness
Although it is called a 5150 in California, there are different terms for this hold in other states. For example, in Florida, inpatient hospitalization is often referred to as "Baker acted," referring to the Baker Act law on mental health hospitalization.