I don't understand why did prophet, being a mercy to all (not just to Muslims), allow his followers to have sex with their female slaves? They could be used just as servants. They could be all released (for money or no money). They could be given options: be free, stay with me and/or be my wife/concubine, or return to your kith and kins. But hadiths and Islamic history doesn't seem to indicate that they were given options or they had any say about their fates. Rather they were viewed as properties captured from enemy and were often sold to others (e.g. prophet sold women and children of banu Quraida) or distributed among the Muslim armies as sex-slaves.
Important thing you must realize is that in Islam [In Submission to God], there is no slavery except to the Most High. The Prophet Muhammad never told people to see their slaves as slaves and let alone as "objects", as such, in a Hadith he says how none should say "my slave" or "my slave-girl" but rather say "my servant", "my girl", and "my young man", and "my young girl".
None of you should say: My bondman and my slave-girl, for all of you are the bondmen of Allah, and all your women are the slave-girls of Allah; but say: My servant, my girl, and my young man and my young girl.
-Sahih Muslim 2249a
The idea and main plan of Prophet Muhammad was to essentially end slavery. As such, he placed a great deal on telling people to treat their slaves as brothers and as sisters, and as humans. The Prophet Muhammad also says how there is no expiation for hitting a slave except for freeing him. It is also noted how the Prophet Muhammad said that however kills his slave, then that person who killed his slave should be killed.
Abu Dharr narrated that the Prophet Muhammad said:
"Allah has made some of your brothers as slaves under your care. So whoever has his brother under his care, then let him feed him from his food, and let him clothe him from his clothes. And do not give him a duty that he cannot bear, and if you give him a duty he cannot bear, then assist him with it."
-Jami` at-Tirmidhi 1945
The Prophet Prophet Muhammad said, "The expiation for beating or slapping a slave on the face for something he has not done is to set him free."
-Riyad as-Salihin 1605
The Prophet Muhammad said: 'Whoever kills his slave, we will kill him, and whoever mutilates his slave, we will mutilate him.'
-Sunan an-Nasa'i 4738
You must truly understand that the Holy Quran recognizes slavery as a source of injustice, as it places the freeing of slaves on the level as feeding the poor.
And what will make you realize what ˹attempting˺ the challenging path is? It is to free a slave, or to give food in times of famine to an orphaned relative or to a poor person in distress, and—above all—to be one of those who have faith and urge each other to perseverance and urge each other to compassion. These are the people of the right. As for those who deny Our signs, they are the people of the left.
As such, with regards to your question on how the Prophet Muhammad told his followers to have sexual affairs with female slaves, well, this isn't the way you may think of, for they were never allowed to go to a female slave and force them into prostitution, for this would greatly be going against the laws of God stated in the Holy Quran,
And let those who do not have the means to marry keep themselves chaste until Allah enriches them out of His bounty. And if any of those bonds-people in your possession desires a deed of emancipation, make it possible for them, if you find goodness in them. And give them some of Allah’s wealth which He has granted you. Do not force your ˹slave˺ girls into prostitution for your own worldly gains while they wish to remain chaste. And if someone coerces them, then after such a coercion Allah is certainly All-Forgiving, Most Merciful ˹to them˺.
The Holy Quran also encourages the marriage towards righteous slave men and women, so this truly gives us the notion of how the intention of the Prophet Muhammad was never to make female slaves as sexual slaves but rather that they may be righteous and be married to a righteous person so that they may be free from slavery.
Marry off the free singles among you, as well as the righteous of your bondmen and bondwomen. If they are poor, Allah will enrich them out of His bounty. For Allah is All-Bountiful, All-Knowing.
The mission of Prophet Muhammad was to set forth the ultimate and divine message of God, and to bring about Peace and Submission to God. The main duty of Islam [In Submission to God] is to free everyone from slavery and to end it as a whole, by taking small steps. We must understand that slavery was a major part of the 7th century socioeconomic system, and abolishing it would not have been practical. As such, most interpretations of the Holy Quran agree that the Holy Quran envisions an ideal society as one in which slavery no longer exists.
Righteousness is not that you turn your faces toward the east or the west, but [true] righteousness is [in] one who believes in Allah , the Last Day, the angels, the Book, and the prophets and gives wealth, in spite of love for it, to relatives, orphans, the needy, the traveler, those who ask [for help], and for freeing slaves; [and who] establishes prayer and gives zakah; [those who] fulfill their promise when they promise; and [those who] are patient in poverty and hardship and during battle. Those are the ones who have been true, and it is those who are the righteous.
Zakah expenditures are only for the poor and for the needy and for those employed to collect [zakah] and for bringing hearts together [for Islam] and for freeing captives [or slaves] and for those in debt and for the cause of Allah and for the [stranded] traveler - an obligation [imposed] by Allah . And Allah is Knowing and Wise.
It is not for a believer (Muslim) to kill any believer, except by mistake. Whoever kills a believer by mistake, then, a believing slave has to be freed, and the blood money must be paid to his family, unless they forgo it.If he (the victim) belongs to a people hostile to you and is a believer, then, a believing slave has to be freed. If he (the victim) belongs to a people between whom and you there is treaty, then, blood money is to be paid to his family, and a believing slave to be freed. Whoever does not find one has to fast for two consecutive months. This is repentance prescribed from Allah’s side. Allah is All-Knowing, All-Wise.
Allah will not impose blame upon you for what is meaningless in your oaths, but He will impose blame upon you for [breaking] what you intended of oaths. So its expiation is the feeding of ten needy people from the average of that which you feed your [own] families or clothing them or the freeing of a slave. But whoever cannot find [or afford it] – then a fast of three days [is required]. That is the expiation for oaths when you have sworn. But guard your oaths. Thus does Allah make clear to you His verses that you may be grateful.
Therefore, of all these verses it is quite clear that the ultimate duty of Islam [In Submission to God] is to free upon slaves, and not to keep them in bondage for ones own sexual desires. For if such a person were to do that then they are going against the laws of God and they would not be upon that path of righteousness. As such, the Prophet Muhammad was an exemplary guide on the freeing of slaves. Following his noble approach, the Prophet's beloved companions also exemplified the many ways in which people could honour the instructions set forth by God within the Holy Quran to help free those trapped in bondage.