True, that is very unfortunate for such a thing to happen.
However, no justice system is going to be completely perfect all the time, and the populace is better off with some innocents (sadly) executed than thousands of murderers and rapists having the potential to be let out of jail and potentially commit more atrocities. The prison system does nothing to improve their mindsets (they arguably end up worse people than before, due to the horrendous environment they're placed into) and unfortunately, there's little, if anything, that can be done to fix the failings of the prison environment.
Ideally, reforms could be made to the prison system to make it rehabilitative, as opposed to a depriving and dehumanizing environment that breeds angrier, more deadly criminals, but since that's very unlikely to happen, these prisoners should not be returning to society; they come in bad and would be coming out even worse.