Gary Anderson, 53, harassed prosecutor Stewart Houston and his wife Christel for more than a year after becoming convinced they had sided with his ex-wife during his divorce.
Anderson, of Cartland, Lanarkshire, moved into the street in Biggar where the Houstons lived in 2002 but moved out when he split from his wife Patricia in 2006.
Mr Houston, 66, retired from his position at Lanark Sheriff Court in 2008 after a successful career spanning 26 years. The father-of-three prosecuted hundreds of cases and was even nicknamed "the Prince of Darkness" by defence lawyers whose clients clashed with him in court.
The couples had remained friends, although the Houstons maintained more regular contact with Mrs Anderson.
But as the divorce became increasingly bitter, unemployed Anderson began plaguing them with texts, letters and threats.
The couple contacted police in 2012, who warned off Anderson, but officers were forced to speak to him again when he continued pestering his former neighbours.
He has now appeared at Lanark Sheriff Court, where he admitted causing the Houstons fear and alarm by repeatedly texting, repeatedly sending letters, and going to their home uninvited between January 2012 and April 2013.
Depute fiscal Paul Service said Anderson believed his ex-wife was confiding in the Houstons about their divorce and passing on details about custody of their two sons.
He said: "Mrs Houston received messages on her mobile from Mr Anderson in January 2012.
"The messages were not threatening but were enough for the couple to contact police because of the repeated requests for meetings with Mr Houston.
"Two letters also appeared at the couple's property which had been hand-delivered by Mr Anderson, who was then living 14 miles away from them.
"Anderson also appeared at the couple's home at night when Mrs Houston was alone and knocked on the window demanding a meeting with her husband, which alarmed her."
Police warned Anderson off in December 2012 but in March the following year he wrote to them and sent flowers with the message: "I apologise, things must change."
Defence lawyer Archie Hill said: "This is a case where he has done this recklessly rather than intentionally. He is a former neighbour and considers himself as a friend.
"They keep in touch with his ex-wife and he believed she was trying to poison their minds about his contact with his sons.
"He accepts they didn't want to know about this and that he harassed them over it."
Sheriff Paul Reid deferred sentence for a year for good behaviour.
He added: "These were circumstances that you misunderstood and overreacted to. This is not the way you should have behaved.
"The Houstons do not want to hear from you and I will continue the bail condition that you must not contact them in any way whatsoever.
"If you do then you will be brought back here and the prospect of you being liberated are somewhat distant."
Anderson refused to comment.