Included in the total is more than £1m spent by the Scottish Government challenging legal action by three men involved in the administration and subsequent takeover of Rangers FC.
The figures, revealed following a freedom of information request by The Scotsman, cover the most costly and high profile court cases brought against the Government prior to the election.
Legal fees, advice from lawyers and any payment of costs awarded against the Scottish Government which total more than a minimum figure of £50,000 per case are included in the £5.8m overall figure.
The sums were described as “eye-watering” by Scottish Labour, with the Scottish Conservatives labelling it a “colossal wasting of taxpayer’s money”.
Scottish Labour’s justice spokesperson Pauline McNeill said: “The number of cases being brought against the Scottish Government and the huge sums being awarded against it are extremely worrying. The government has a right to defend itself but the vast sums incurred are nothing short of eye-watering.
“At a time when public finances are tight it is particularly egregious that failures from Government are resulting in millions of pounds being lost.
“With many excluded from taking legal action due to lack of funds, this extraordinary expense will come as a slap in the face.
“From the chaos with the SQA to the worrying acceleration in new Covid cases, each week exposes a new failure from the SNP and the avoidable legal costs being recorded by the Scottish Government are a stark testament to that.”
The highest single cost of £825,949 is linked to legal claims made by tenant farmers that they should have been paid compensation following a change to the law around the Agricultural Holdings (Scotland) Act 2003.
The case eventually ended in the Supreme Court, with the Scottish Government winning its defence.
In total, the legal fight had cost at least £975,000 when other court cases are included.
Challenges to the named persons scheme (£482,000), minimum alcohol pricing (£494,000), the construction of the Menie Links windfarm challenged by Trump International Golf Club (£363,000) were among the most costly actions defended by the Scottish Government.
An analysis of the listed cases show that around two thirds would be considered victories for the Scottish Government or decisions in favour of the Lord Advocate.
However, Scottish Conservative MSP Murdo Fraser said it was a indication of the SNP “continuing to plough on regardless” in “indefensible” cases.
He said: “These astonishing figures lay bare the SNP Government’s colossal wasting of taxpayers money when trying to defend their positions in court.
“A fortune of public money has been lost as a result of the SNP continuing to plough on regardless and defending the indefensible in many high-profile cases.
“They knew that their case against Alex Salmond was doomed and the Crown also continued to maliciously pursue innocent men in relation to Rangers administration.
“It shouldn’t have taken an FOI to highlight the millions blown on many cases that the SNP Government never stood a chance of winning. It highlights again their failures to be open and transparent with the public about how they are spending their money.
“Almost £6 million worth of funding has now been lost that should have been available to support vital jobs and livelihoods across Scotland.”
The Scottish Government was also contacted for comment.