Ministers are facing a flood of claims from prisoners for human rights breaches such as "slopping out", after a House of Lords ruling.
Hundreds of prisoners are seeking compensation for slopping out
The Scottish Prison Service had argued the European Convention on Human Rights barred claims made a year after the incident of which inmates complained.
That is the position which applies in England and Wales.
But the House of Lords ruled the Scotland Act, which introduced devolution, did not impose a time bar.
Prison sources indicated the ruling would not cost huge and unforeseen extra sums - but could could eat up the money that has already been earmarked.
The Scottish Prison Service's annual accounts for 2005/06 said it could cost up to £58m to meet payouts to prisoners suing them.
The lack of integral sanitation in many Scottish prison cells has led to the practice of "slopping out" continuing.
Inmates are required to empty out their own sanitary waste from their cells.
In 2004 Barlinnie inmate Robert Napier won a ruling that his human rights had been breached and was awarded £2,000 for the effect of slopping out and prison conditions on his health.
That triggered claims from 1,400 former and serving prisoners and the Scottish Prison Service made cash offers to some of them.
But many cases have been awaiting a legal ruling on whether they were launched too late.
The decision of the Law Lords related to four prisoners who challenged orders made by prison governors and Scottish ministers segregating them - under prison rules - from the mainstream prison population.
The ruling did not directly relate to slopping out - but did so indirectly, by holding that claims of human rights breaches under the European Convention were not covered by a one-year time bar if they were launched under the Scotland Act.
Solicitor Tony Kelly, who acted for the prisoners, said the ruling was a 3-2 split decision by the five top judges.
He said hundreds of actions against Scottish ministers, mostly to do with slopping out, had been frozen pending the outcome of the House of Lords case.
If the law lords had instead upheld a Court of Session ruling and backed the view of Scottish ministers, many of these cases would have been blocked.
A Scottish Government spokesman said it is considering the wider implications of the judgment.
"There is already provision within the SPS accounts for claims under ECHR legislation.
"The new Scottish Government has already made considerable financial commitments to providing a prison estate fit for purpose for the 21st century."