This beautiful anecdote appears in Tadhkirat al-Auliya of Shaykh Farid ud din Attar1 (r.a)
In his lifetime, Sufyan al-Thawri2 (r.a) was known for showing compassion towards God’s creatures. One day he saw in the market a bird in a cage, fluttering and making a pitiful sound. He bought it and set it free. Every night the bird would come to Sufyan’s (r.a) home and watch all night while Sufyan (r.a) prayed, perching on him from time to time. When Sufyan (r.a) died and was being borne to the grave, that bird insisted on joining the procession and wailed pitifully along with the rest of the mourners. When Sufyan (r.a) was committed to the dust, the bird dashed itself to the ground. A voice issued from the tomb, “Almighty God has forgiven Sufyan (r.a) for the compassion he showed to His creatures.” The bird died too and was buried alongside Sufyan (r.a).
1- Farid al-Din Attar(1119-1230 C.E) was a persian Islamic Mystic, and one of the greatest poets of Persia, who had tremendous influence upon the later Persian poetry.
2- Sufyan al-Thawri(715-778 C.E) was a Islamic Jurist, a strict Ascetic and a true Saint of God, he was also noted for founding the Thawri School of Islamic Jurisprudence, which remained active until 200 years of his death.