The Teacher said this concerning Kokālika while living in Jetavana.
The story of Kokālika will be made clear in the Takkāriya Jātaka in the Chapter of the 13.
Thinking, "I will come after bringing Sāriputta and Moggallāna", Kokālika came to Jetavana from Kokālika country, paid respect to the Teacher, approached the Elders and said, "Friends, the people dwelling in Kokālika country summon you. Come, we will go."
"You go, friend, we are not coming."
Rejected by the elders, he went by himself only.
Then, the bhikkhus started this discussion in the Dhamma hall:
"Friends, Kokālika is unable to live both with or without Sāriputta and Moggallāna. He is not able to associate nor dissociate (with them)."
The Teacher came and asked, "Monks, what type of speech has come up that you are now sitting together? (what are you talking seated together now?)"
When it is informed to him, "we are discussing this...", he said, "Monks, not only now, in the past too Kokālika was unable to live neither with nor without Sāriputta and Moggallāna," and he recounted the story of the past.
In the past, when Brahmadatta was reigning in Bārāṇasī, the Bodhisatta was reborn as a tree-deva (living) in a certain forest.
Not far from his (the Bodhisatta's) mansion, another tree-deva lives on a certain foremost tree which bears fruit without flowers.
A lion and a tiger also live in that jungle.
Out of fear for them (of them), no one does any farming nor cutting of tree there; it is not possible to turn back and look.
Furthermore, those lion and tiger kill various beasts and eat them. They would abandon the remainder of what they could not eat and go off.
Because of that, that jungle becomes stinking of impure carcasses.
Then, the other tree deva, which is foolish and not knowing the difference bwteen a good reason and a bad reason said to the Bodhisatta one day,
"My friend, our (no?) jungle, on account of those lion and tiger, has become stinking with impure carcasses, I will cause them to go away."
The Bodhisatta replied, "My friend, on account of these two our mansions are protected. When they are driven away, our mansion will be destroyed. Not seeing the foot prints of the lion and the tiger, human beings will cut down the whole forest, make into a clear open space and do agricultural activities. You please do not do so." Saying this, the Bodhisatta uttered the first two verses:
Herein, yena mittena saṃsagga means by the cause of association, reason of association with whoever evil friend; the meaning is the state of engaging in association with him by seeing, listening, body, conversation, enjoyment (eating) these five ways of association.
Yogakkhema means bodily and mental happiness.
For here, "yogakkhema" is intended to mean the state of being safe from that yoke of suffering
Vihiyyati means is destroyed
Pubbevajjhābhavaṃ tassa, rakkhe akkhīva paṇḍito means the predominance/contact of that evil friend; by that, one's own gain, reputation and life can be overcome; in the way that one does not predominate/contact that, in that way a wise person would protect in the very first instance as if protecting one's own eye.
In the second verse, yena means the reason of association with whoever good frined.
Yogakkhemo pavaḍḍhati means the bodily and mental happiness increases.
Kareyyattasamaṃ vuttiṃ means In the way that one does his own livelihood and the conduct of use and enjoyment (?) , in the same way in all the duties (what is done) of that good friend, the wise person should do all and even exceeding that, but should not do what is less than that.
Even though (pi) When the Bodhisatta explained the reason thus, that foolish deva, without taking this advice into consideration, and one day showed frightful visible object/image (a terrifying spectacle) and caused the lion and tiger to be driven away (put the lion and tiger to flight).
When the human beings did not see their footprints (no longer saw their tracks), they knew (realised), "the lion and tiger have gone to another jungle", and they clear out one side of the jungle.
The deva apporached the Bodhisatta and said, "My friend, I did not heed your words and caused them to be driven away. Now,, knowing their departure, the humans are cutting down the forest, what should be done?"
"Now they are living in a forest named such and such, having gone there, bring them back!"
When that was said, he went and stood in front of them, held up his hands in salutation and uttered the third verse:
Herein, byagghā refers to both lion and tiger, but only addressing (alapantī) the name of tiger is said.
grammatical explanation: -avho ending here is the same as the -atha case ending : the former being 2pl. imp. mid. and the latter 2pl. imp. act. = Turn back! or Return!
paccupetha = puna upagacchatha = approach again (this is yet another reading)
Let the humans not cut down the forest which we dwell is now without-tiger (nibyaggha) due to your absence!
Furthermore, tiger kings like yourselves should not be without a forest which has become your dwelling place (nibbana = nir + vana?) due to the fact of running away from your own dwelling place.
Being begged thus by the devatā, they simply rejected him saying, "You go, we will not come with you."
The devatā returned alone to the forest.
In just a few days, the humans cut down the entire forest, made it into paddy fields and did farming.
Having told this Dhamma teaching and made evident the truth, the Teacher gave the connection to the Jātaka,
At that time, the unwise devatā has become Kokālika, the lion Sāriputta, the tiger Moggallāna, while I was precisely the wise devatā.