Story of Shiva feeding stone elephant with sugarcane is found in the Halasyamahatmyam. The story depicts Lord Shiva’s love and compassion for his devotees.
Once, when the king of renowned Pandya Empire in South arrived for his regular morning prayers at the famous Madurai Meenakashi Temple, Lord Shiva appeared on the scene in the guise of an ascetic, just outside the sanctum sanctorum.
When he blocked the path of the king, the royal guards ordered Him to move away, but the ascetic refused. The king demanded, “Who are you?”
“I am an ascetic of great occult powers,” replied the ascetic. “I am subservient to none, and the Lord of all. I am omnipotent!”
At this point, a farmer brought a sugarcane and offered it to the king. Determined to belittle the ascetic, the king asked Him to command the huge sculpture of the elephant in front of the shrine to eat the sugarcane out of his hand.
The mystic immediately ordered the stone elephant to do so, whereupon the latter momentarily came to life, snatched the sugarcane from the king’s hand and ate the sugarcane.
The king’s egoistic refusal to concede the ascetic’s power buckled, because he realized then that the sage was none other than Lord Shiva himself.
He begged the Lord for forgiveness.
The Lord blessed the king, saying that He was ever eager to meet His devotees, in particular the devout and just ruler who had always been very dear to Him.
Source - My Mother, My Master By Swami Pranavamritananda Puri