If a person been hospitalized under 5150, they are held for 72 hours. If the treating providers feel that more treatment would be necessary, they can get a hearing. The default is just let them go. The hearing is before a panel of doctors at that facility. The patient, at this point, cannot challenge the decision because it is a medical decision based on immediate need. The panel of doctors will make a recommendation as to the length and scope of additional treatment.
If the patient is deemed seriously impaired the facility notifies the family that the condition is If not permanent, at least long term. They must file, in court, for Guardianship/Conservatorship. This means a full blown hearing with attorneys, witnesses and all kinds of opportunity to be heard. If family cannot be found or isn't interested, the Court can appoint a state representative and the state will be appointed.
In practice, it works out for people that are seriously mentally ill that the state will get a conservatories over the finances of the ill person only. That way no one can get them to sign a bogus contract and take their disability payment. They will not get a guardianship over the health and safety of the person, leaving them to overdose in the streets.
This should answer your questions.