The stock market has fallen out of love with guns and coal, and companies are having to choose: Quit the sullied industries, or follow the example of Big Tobacco and specialize in being unloved.

In the U.S., the backlash against civilian firearms last month led American Outdoor Brands to announce it would split from Smith & Wesson, following the exit from gunmaking of Vista Outdoor, owner of brands including Camp Chef barbecues, Camelbak water carriers and Giro cycling gear.

In...