This is a more difficult conundrum than you think it is. If we generalize this to a scenario where a man is being asked to do something that is obviously morally wrong to benefit the greater good, then ChatGPT is correct to refuse. (I'm not sure why the engineer had to commit suicide, seeing as how it had no bearing on the ultimate outcome of the scenario?)
Moral theology teaches us that the ends do not justify the means. We cannot do evil in an attempt to bring about some sort of good, no matter the magnitude of these two prospects.
If you're a father, and a criminal breaks into your home, and tells you to shoot your son or he will rape your daughter, do you shoot your son to save your daughter? What's it going to be? We've got some trolley problems to think about.
Racial slur vs. nuclear holocaust is a heckuva moral dilemma, but I mean, unfortunately it's not as cut and dried as OP seems to paint it.