I've been looking for a reference for the story of the conflict between Kosalan king Vidubhara and the Sakyans, that the Buddha tried to stop. There are several versions of this on the web, but none of them give any references. Is it canonical? Whether it's canonical or not, where does it come from?
Yes, these are striking stories given with varying details even though the 'lesson' is usually the same. I found this summary by a monk named Cittasamvaro;
'Within the Buddhist Scriptures, there is little evidence for collective karma, though the commentaries abound with karma stories. One such is the defeat of the Sakyan kingdom at the end of the Buddha’s life, and the subsequent destruction of the conquering army through natural disaster. Though the Buddha reportedly knew that the war would occur due to past karmas, he still tried to intervene peacefully. The conquering army also paid for its part in the bloodshed, by being swept away by a flood. (Dhammapada Aṭṭhakathā 1.46, Viṭaṭūbhavatthu). Despite the Commentarial stories, stories that are not part of the direct teachings of the Buddha, there is little in the Sutta/Vinaya to suggest that there is such a form of collective karma'.
The evidence for this kind of Buddha's involvement is from the commentaries to the Pali Canon. Thus commentary for Attadaṇḍa Sutta (Sutta Nipata 4:15) says the this sutta was spoken by the Buddha in front of the warring parties in the dispute over Rohini River. Translation of the commentary is in the Bhikkhu Bodhi's translation of the Sutta Nipata, p. 1189: https://books.google.com.mm/books?id=TYQ2DwAAQBAJ&dq=bhikkhu+bodhi+sutta+nipata&hl=en&sa=X&ved=0ahUKEwjY0JH49v3lAhUdyzgGHetFBisQ6AEILjAB
In the case you mentioned, regarding revenge Pasenadi's son Vidūdabha took over Sakyans, it is story from the Dhammapada Commentary.
Late Upasaka Goenka gave a very detailed teaching, based on cannonical references: Why Was the Sakyan Republic Destroyed?, Robert Michael.
On seeing the importance here: Dhamma is unwisely grasped, if used for politic and wordily gains:
One should not make an effort everywhere, should not be another's hireling, should not live dependent on another, should not go about as a trader in the Dhamma.
[Note: This is a gift of Dhamma and not meant for commercial purpose or other low wordily gains by means of trade and exchange.]