It varies on who you're talking to. Some people may take it to someone else (e.g. police) and they'll conduct their own policies to deem if you're eligible for the involuntary civil commitment hold for a maximum of 72 hours. No court order is necessary to hold you in an emergency room for 72 hours. It is possible that within those 72 hours someone could petition that you should stay longer, and this will have to go through a judge. Otherwise you'll be evaluated, proceed with the involuntarily hold, and look for outpatient care. States handle this differently. After some period the involuntarily commitment is supposed to be drop. Some states range from two weeks to an upwards of six months. There's a good site to filter this information state-by-state. I'll link it below.
If you were to speak with a psychologist, therapist, or a psychiatrist about your ideation. In most case scenarios these are safe to talk about. It is when you go to planning is when you're in murky water that could make it where that doctor involuntarily commits you. Quite honestly, this is up to the judgement of where you're at when going through therapy. In the case of just saying that you've felt suicidal, you may not be subjected to an involuntarily hold.
Personally I would avoid talking about it unless I know the person quite well. I find in cases that people who are talking to someone who is suicidal, they tend to put that leverage onto someone else. Calling the police because your friend is suicidal will only exasperate the emotions they are feeling. Perhaps triggering them to catch the bus when they're out of the hospital.
[1]
Standards for Involuntary Commitment (Assisted Treatment) State-by-State (Source Treatment Advocacy Center) - https://mentalillnesspolicy.org/national-studies/state-standards-involuntary-treatment.html