A term for the situation is an ill wind.
That's short for the proverb ‘It's an ill wind that blows nobody any good.’ Wiktionary paraphrases that as:
An action or occurrence must be very bad indeed if it brings no benefit to anyone.
According to The Phrase Finder, this is a many-centuries-old sailing metaphor, meaning that:
a wind that was unlucky for one person would bring good fortune to another.
The term is often used when mentioning the good outcome, as in these examples from The Free Dictionary:
The rain caused flooding, but it may help the farmers. It's an ill wind, as they say.
The fire destroyed half the village. For the builders business has never been better. It’s an ill wind…
But it's an ill wind; I recovered and married one of my nurses from that hospital.