How does a therapist handle confidentiality in cases in which the client expresses thoughts of self harm?

Legal Issues first. If one is potentially harmful to one's self or to others it must be reported and the person is taken to the nearest facility for psychiatric evaluation. Aside from that exception it is a matter of law that information given to a therapist remains confidential unless released by the patient. If the patient is a minor, parents or guardians have access. Dss can access it if abuse is reported.
Safety. Confidentiality does not supersede patient safety or the safety of others. Therapists (and physicians) need to evaluate the credibility of the statement and the patient's likelihood of acting on that statement. If there is doubt, the therapist would err on the side of patient safety.