"It may be that if he divorces you his Lord will give him, in [your] stead, wives better than you: [such as are] muslim, faithful, obedient, penitent, devout and given to fasting, virgins and non-virgins." Qur'an 66:5
The two wives who were condemned in the verses 3, 4 and 5 in Sura 66 are Hafsa daughter of Omar and 'ayisha daughter of aabu Bakr. This fact is mentioned in Tasfeer al-Tabari and Tafseer al-Qurtubi, and all other Tafseer books.
Why did the Prophet not divorce them? Allah (SWT) wanted to make them a test for verifying the faith and obedience of Muslims. They became the leaders of the enemies of imam Ali (AS) especially in the battle of Camel. Real believers followed Imam Ali (AS) while many Muslims went astray by joining the army of A'yisha to fight against Imam Ali (AS).
Distinguishing good Muslims from others needed a leadership for the good Muslims which is the leadership of Imam Ali, and a leadership for others which was A'yusha, Hafsa and their group.