One has to read all the adjoining verses in conjunction. Verses 4:23 to 4:25 are about women that a man is forbidden to MARRY. Verse 4:24 is about married slave women who had been captured at the battlefield itself and whose previous marriages were made null and void because they were unable to go back or had converted to Islam in captivity and didn’t want to go back to their non-Muslim husbands. Muslim women suffered the same fate when they were captured by the enemies. That is why Quran hints at this and says that Muslim should not grieve over what they have lost. If there was a treaty, the prisoners of war were always exchanged. It is only when there was none, that prisoners of war were taken as slaves. Even so, one month had to pass before a slave woman could marry another man, allowing sufficient time for her family to seek her freedom, if they wanted to. These women were either freed, released on payment of ransom, or exchanged with other Muslim prisoners held by the enemy. Here, Quran is allowing a Muslim man to MARRY from among these women. Verse 4:25 clearly explains this and creates an additional condition that besides the consent of the woman, the consent of her master/guardian should also be obtained. The master/guardian was not always the person who slept with her. This is clearly exemplified in this Hadith: “There are three people for whom there is a double reward; a person belonging to the Ahl al-Kitab who believes in his own prophet and believes in Muhammad, and the slave owned by another when he performs his obligations towards Allah and his obligations towards his master, and the man who has a slave girl with him, that he teaches her good manners and instructs her well in polite accomplishment, and he educates her and gives her a good education, then he sets her free and marries her off.” This tradition is repeated in Bukhari at least six times.
See also Verse 4:19, which says:
[4.19] O you who believe! it is not lawful for you that you should take women as heritage against (their) will, and do not straiten them in order that you may take part of what you have given them, unless they are guilty of manifest indecency, and treat them kindly; then if you hate them, it may be that you dislike a thing while Allah has placed abundant good in it.
slavery is banned in every muslim country.