The story goes that Leo planned to get John killed. He dummied up some plans for the reconquest (I would not say liberation in this case) of Damascus and implicated John in a plot to betray the city to Christian soldiers. The Caliph wound up with the plans and ordered John's right hand to be chopped and displayed as a warning to other traitors.
John was deeply devoted to the Theotokos. He prayed at her icon, enlisting her support for divine intervention to restore his severed hand. Sure enough, the hand grew back. In gratitude, he had a silver facsimile of his hand attached to the riza -- i.e. the protective and ornamental screen placed over holy icons -- of the icon. That particular icon, now located at the Hilandar Monastery at Mount Athos in Greece, is called the Bogorodica Trojerucica, the Three-handed Theotokos.
Some spoilsport scholar has demonstrated that John Damascene had already left Damascus for the Mar Saba Monastery before the iconoclast controversy broke out, but I follow in the proud tradition that does not allow the truth to get in the way of a good story.