Prisoners who are too mentally ill to execute remain on death row for decades for two main reasons. The first is that their legal representatives are preparing appeals against the death sentence and exploring all possible avenues first to delay and then to overturn the judgment. This is a major reason why prisoners of all types stay on death row for such a long time.
The second reason, which is specific to mentally ill prisoners, is the result of compromise in a system which prohibits people who are mentally incompetent from being put to death but has not provided a clear and consistent alternative. A stalemate between defense lawyers who argue that their client's mental illness should result in their being removed from death row and state authorities who are adamant that they should be executed often results in neither.
The Marshall Project, a nonprofit organization that focuses on criminal justice in the United States, has highlighted the case of Raymond Riles (link below), who has been on death row in Texas for forty-five years. A new sentence has recently been ordered for Riles (see CNN link below), but as the Marshall Project makes clear, this is no guarantee that he will be taken off death row, and the same issues affect many other inmates.