Question: Those who slander chaste women are cursed forever [in this life and the Hereafter] according to Sura 24:23. But Sura 24:5 says that they can be forgiven if they repent after they have been beaten with 80 stripes. since it says to let them come back into full rights as members of society, restoring their right to testify, because Allah is (also) oft-forgiving, most Merciful.
The earthly forgiveness would not have any foundation or counterpart if Allah would not extend forgiveness as well. That is the very basis on which He commands earthly forgiveness.
Answer: Simple two different states 24:4-25 they got the earthy punishment and extended forgiveness. While 24:23-25 talk about the hypocrites who do not beleive in God and slander the chast of Asha the wife of the prophet who is one of the most holy women in history.
State 1: Mulsims who slander chaste woman:
24:4 And those who launch a charge against chaste women, and produce not four witnesses (to support their allegations),- flog them with eighty stripes; and reject their evidence ever after: for such men are wicked transgressors;- وَالَّذِينَ يَرْمُونَ الْمُحْصَنَاتِ ثُمَّ لَمْ يَأْتُوا بِأَرْبَعَةِ شُهَدَاء فَاجْلِدُوهُمْ ثَمَانِينَ جَلْدَةً وَلَا تَقْبَلُوا لَهُمْ شَهَادَةً أَبَدًا وَأُوْلَئِكَ هُمُ الْفَاسِقُونَ
24:5 Unless they repent thereafter and mend (their conduct); for Allah is Oft- Forgiving, Most Merciful.
إِلَّا الَّذِينَ تَابُوا مِن بَعْدِ ذَلِكَ وَأَصْلَحُوا فَإِنَّ اللَّهَ غَفُورٌ رَّحِيمٌ
State 2: hypocrites who slandered the wife of the prophet.
24:23 Those who slander chaste women, indiscreet but believing, are cursed in this life and in the Hereafter: for them is a grievous Penalty,-
إِنَّ الَّذِينَ يَرْمُونَ الْمُحْصَنَاتِ الْغَافِلَاتِ الْمُؤْمِنَاتِ لُعِنُوا فِي الدُّنْيَا وَالْآخِرَةِ وَلَهُمْ عَذَابٌ عَظِيمٌ
24:24 On the Day when their tongues, their hands, and their feet will bear witness against them as to their actions. يَوْمَ تَشْهَدُ عَلَيْهِمْ أَلْسِنَتُهُمْ وَأَيْدِيهِمْ وَأَرْجُلُهُم بِمَا كَانُوا يَعْمَلُونَ
24:25 On that Day Allah will pay them back (all) their just dues, and they will realise that Allah is the (very) Truth, that makes all things manifest. يَوْمَئِذٍ يُوَفِّيهِمُ اللَّهُ دِينَهُمُ الْحَقَّ وَيَعْلَمُونَ أَنَّ اللَّهَ هُوَ الْحَقُّ الْمُبِينُ