Is rape always immoral? Could it be justified under jurisprudence as punishment
Someone might say that punishment should fit the crime and therefore that raping rapists is a just punishment. Someone might also say that torturing torturers is a just punishment. My reaction is that examples like this show the unacceptability of a strict "eye for an eye" notion of justice. Torturing someone as a form of punishment strikes me as depraved; so does raping a rapist. Torture and rape are crimes that show an utter and complete lack of respect for the victim's humanity. That's something that an acceptable judicial system should avoid, in my opinion.
As for your hypothetical about rape in the case of near-extinction, I don't feel the force. Why is the continued existence of humanity so important that it would justify raping an unwilling woman and forcing her to carry a baby? Is the sort of "civilization" that would stoop to such things work preserving? What's so hot about humanity from the point of view of the cosmos?
Are there any circumstances that would justify a different conclusion? Perhaps there are hypotheticals so horrifying that the answer is yes. But that's the point: those hypotheticals would indeed be utterly horrifying. They're unlikely (one hopes!) to give us any guidance in the kinds of situations we're likely to face.