The Quranic law regarding murder is that the heirs of the victim are given the choice to take revenge on behalf of the victim by killing the murderer. Or they can forgive and accept blood money instead.
Only the murderer himself can be killed in retaliation for his crime, and it is not permissible to kill a different innocent person. This is common sense and agreed upon. For example it is known that the Prophet ﷺ executed a male for the murder of a female, and did not kill some random woman instead:
أن النبي صلى الله عليه وسلم قتل يهوديا بجارية قتلها على أوضاح لها
The Prophet (ﷺ) killed a Jew for killing a girl in order to take her ornaments.
— Bukhari and Muslim
Similarly he stated that killing anyone other than the murderer is a grave sin:
إن أعتى الناس على الله عز وجل من قتل في حرم الله، أو قتل غير قاتله، أو قتل بذحول الجاهلية
The most evil in the sight of Allah include: a person who killed within the sanctuary, a person who killed someone who was not a murderer, and a person who killed someone as revenge for the feuds of the times of ignorance
— Musnad Ahmad
And the Quran forbids transgression in retaliation, and killing innocents is a clear form of transgression:
ولا تقتلوا النفس التي حرم الله إلا بالحق ومن قتل مظلوما فقد جعلنا لوليه سلطانا فلا يسرف في القتل إنه كان منصورا
And do not kill the soul which Allah has forbidden, except by right. And whoever is killed unjustly - We have given his heir authority, but let him not exceed limits in [the matter of] taking life. Indeed, he has been supported [by the law].
— Quran 17:33
فقال ابن عباس ، وأكثر المفسرين : معناه لا يقتل غير القاتل وذلك أنهم كانوا في الجاهلية إذا قتل منهم قتيل لا يرضون بقتل قاتله حتى يقتلوا أشرف منه .وقال سعيد بن جبير : إذا كان القاتل واحدا فلا يقتل جماعة بدل واحد وكان أهل الجاهلية إذا كان المقتول شريفا لا يرضون بقتل القاتل [ وحده ] حتى يقتلوا معه جماعة من أقربائه
Ibn Abbas and many of the exegetes said: This means that do not kill anyone other than the murderer. And the practice of the times of ignorance was that when a murder occurred the victim's tribe were not satisfied with killing just the murderer until they had killed someone more reputable than him.
And Sa'id ibn Jubayr said: If the murderer is one man then do not kill a group in-place of the single man. And the practice of the times of ignorance was that if the victim was reputable then his heirs were not satisfied with killing the murderer alone rather they also killed with him a group of his relatives.
— Tafsir al-Baghawy
What does the Quran mean when it says,
"the free for the free, the slave for the slave, and the female for the female"
This means that the murderer is to be executed when the victim and murderer are equals. If a free person kills a free person, then that free person must be executed. When a slave kills a slave, the murdering slave must be executed. When a female kills a female, the murdering female should be executed.
The verse says nothing explicitly about what must be done when the victim and murderer are unequal. e.g. if a free man kills a slave or vice versa. However on this there are three interpretations:
- Retaliation is carried out. i.e. the murderer is killed even though he/she is not the same genus as the victim. That is because the Quran also says "life for a life" (5:45) and the Prophet ﷺ said "The blood of every Muslims is equal" (Ibn Majah 2683). And obviously there is the hadith already cited above that the Prophet ﷺ executed a man for the murder of a woman.
- Retaliation is not carried out in some of these cases however is carried out in other cases. In the cases where retaliation is not carried out the murderer will be given a Ta'zir (imprisonment and flogging) and will pay blood money.
- Retaliation is carried out if the heirs of the victim agree to pay the difference in blood money. When they do so they will be permitted to execute the murderer.
Retaliation in all the above means executing the murderer.
It seems it is replacing the previous rule given to Jews
as the Hadith literature mentions: https://www.sunnah.com/bukhari/87/20.
That hadith says:
كانت في بني إسرائيل قصاص، ولم تكن فيهم الدية
For the children of Israel the punishment for crime was Al-Qisas only (i.e., the law of equality in punishment) and the payment of Blood money was not permitted as an alternate.
This means that the law of retaliation is the same as that for the Bani Israel, however the law for blood money has been changed. This is about the latter part of the verse:
But whoever overlooks from his brother anything, then there should be a suitable follow-up and payment to him with good conduct. This is an alleviation from your Lord and a mercy. But whoever transgresses after that will have a painful punishment.
This portion of the verse allows for forgiving a murderer and accepting blood money, and this replaces the Jewish law which did not allow for blood money for murder, as recorded in the Torah:
You shall not accept ransom for the life of a murderer, who is guilty of death, for he shall be put to death.
— Numbers 35:31
In reply to your last two paragraphs: An innocent person can never be killed for the actions of another. Neither was that permitted at the time and context of revelation of this verse nor can one be killed today. Rather killing innocents was a practice of Jahiliyya and this verse and others were revealed as a disapproval to that custom.