Two teenagers have gone on trial at the High Court in Edinburgh accused of breaking into a mausoleum in the city's Greyfriars Churchyard.
The case centres on the churchyard mausoleum
The pair are also accused of taking the remains of a body from its coffin, cutting off its head, playing with it and simulating a sex act.
Sonny Devlin, 17, and a 15-year-old who cannot be named for legal reasons, have denied the "violation of a sepulchre".
The case is being brought under common law and the maximum sentence is life imprisonment.
Andrew Henderson, who runs City of the Dead Tours, said he went to the graveyard to get his bike and saw two people, who he identified as the accused, running out of the mausoleum.
He discovered a mausoleum nearby had been broken into and called the police.
Sir George Mackenzie, whose tomb was allegedly violated
When they arrived they found four coffins, one of which had been smashed, and the head of the corpse removed.
A 14-year-old girl told the court that Sonny Devlin said "they had taken a head from someone that was dead at the graveyard".
At Greyfriars, he pulled out a head from behind a gravestone and at one point, was "chucking it around" with another youth or youths.
Another witness, a 15-year-old girl, said Sonny Devlin and his co-accused had been "mucking about" with the head "... making it talk to him".
Both are alleged to have forced open the Mackenzie Mausoleum, where Sir George Mackenzie, a former Dean of the Faculty of Advocates, was laid to rest after his death in 1691, on 30 June 2003.
Mackenzie was a prosecutor for Charles the Second and earned the nickname "Bluidy Mackenzie" for vigorously pursuing Covenanters whom he had tortured to gain confessions.
In Scots law, it is a crime to interfere with a corpse, without the authority of the relatives or executors of the deceased or other lawful authority such as a warrant for exhumation.
The best-known examples of the crime were those committed by "body-snatchers" who removed corpses for use as anatomical specimens.
The trial continues.