إِذَا مَاتُوا وَهُمْ مُوَحِّدُونَ
Provided that they die affirming Allah’s oneness.
Tawhid is the decisive condition. Moral failure and disbelief or shirk do not carry the same ruling. A sinful believer may be liable for punishment, but is not thereby judged to remain eternally in Hell. Ignoring the condition of dying upon tawhid confuses the different ultimate outcomes.