This phrase is used in a wide range of everyday situations. The key is that the lie must be genuinely well-intentioned and cause no real harm.
Social Politeness: This is the most common use. You might tell a friend their new, questionable haircut looks great, or you might make up an excuse for why you can't attend a party rather than saying you just don't want to go. This is seen as tactful, not dishonest.
Family Life: Parents often use white lies with children (e.g., about Santa Claus, or to simplify a complex, scary situation). It's also extremely common for adult children to shield their elderly parents from bad news (financial trouble, a relative's illness) to prevent them from worrying.
Medical Contexts: As mentioned, it's a very common practice to tell a patient a more optimistic version of their prognosis to encourage a positive mindset, which is believed to aid in recovery. The family is usually informed of the full truth separately.
Connotation: The connotation is generally neutral to slightly positive, as it acknowledges the kindness behind the act. However, it can be used in a debate about ethics. Someone might argue, “即使是善意的谎言,也还是谎言” (Jíshǐ shì shànyì de huǎngyán, yě háishì huǎngyán) - “Even a white lie is still a lie.”