Idiom for the phrase "getting a good result from a bad situation or with a bad condition"?
Solution 1:
A well-worn way to put this is: When life gives you lemons, make lemonade.
Or, to match your question: Making lemonade when life has given you lemons.
It may not be quite right for you, since it is often used as a prod towards positive thinking, rather than a statement of results.
Solution 2:
"Flipping the script"
flip the script (third-person singular simple present flips the script, present participle flipping the script, simple past and past participle flipped the script)
(slang) To reverse a situation, especially by doing something unexpected.
source: https://en.m.wiktionary.org/wiki/flip_the_script