Sheriff Derek O'Carroll found a "series of shortcomings" at Aberdeen Royal Infirmary, HMP Peterhead and HMP Glenochil following the death of rapist Giovanni Cocozza.
The 82-year-old died at Stirling Royal Infirmary in March 2011 from a brain haemorrhage he was susceptible to due to long-standing high blood pressure.
Cocozza, who at the time was serving a 10-year sentence, was found to be suffering from incurable lung cancer which had spread to his liver. It was first diagnosed less than 24 hours before his death.
Sheriff O'Carroll, who heard a Fatal Accident Inquiry (FAI) into the death at Alloa Sheriff Court, concluded that the cancer did not contribute to his death and could not have been avoided.
Despite this, the failure to detect it earlier denied Cocozza access to treatment that might have improved his quality of life. He could have been considered for compassionate release, he said.
The sheriff said: "The failure to diagnose that cancer was attributable to the combined effect of a series of shortcomings, both personal and institutional, occurring within Aberdeen Royal Infirmary, HMP Peterhead and HMP Glenochil.
"Had it not been for those shortcomings, it is likely that the existence of the cancer would have been diagnosed earlier.
"The absence of a more timely diagnosis resulted in losing two opportunities. The first was access to treatment, though any such treatment could only have been palliative and not have extended life, though it might have improved the quality. Secondly, he could have been considered for compassionate release."