For example, imagine someone threatened you and told you to kill yourself or else they would throw an atomic bomb or something like that. This would obviously be Haram and wrong, but you are saving the lives of millions of people in exchange of one.
Islam teaches to stand against cruelty and fight for the right. Suicide is a way of running away from a problem. That's why Islam prohibited it. But in some situations when you've to save lives of many others and cost is your own life. You can embrace death. But in such situation you've to keep all options in front of you. You've to find out a way that can save your life and doesn't harm innocent people. But if there is no other way... I guess you can go for suicide. Actually there is a really thin line between the right and wrong decision. You've to understand the difference and decide.