Why were the AhlulBayt (as) Killed

إثبات الهداة: قالَ [الفَضلُ بنُ شاذانَ‌]: حَدَّثَنا عَبدُ اللَّهِ بنُ الحُسَينِ بنِ سَعدٍ الكاتِبُ، قالَ: قالَ أبو مُحَمَّدٍ عليه السلام: قَد وَضَعَ بُنو امَيَّةَ وبَنُو العَبّاسِ سُيوفَهُم عَلَينا لِعِلَّتَينِ

إحداهُما: إنَّهُم كانوا يَعلَمونُ أنَّهُ لَيسَ لَهُم فِي الخِلافَةِ حَقٌّ، فَيَخافونَ مِنِ ادِّعائِنا إيّاها وتَستَقِرُّ في مَركَزِها

وثانيهِما: إنَّهُم قَد وَقَفوا مِنَ الأَخبارِ المُتَواتِرَةِ، عَلى‌ أنَّ زَوالَ مُلكِ الجَبابِرَةِ وَالظَّلَمَةِ عَلى‌ يَدِ القائِمِ مِنّا، و كانوا لا يَشُكّونَ أنَّهُم مِنَ الجَبابِرَةِ وَالظَّلَمَةِ، فَسَعَوا في قَتلِ أهلِ بَيتِ رَسولِ اللَّهِ صلى الله عليه و آله وإبادَةِ نَسلِهِ؛ طَمَعاً مِنهُم فِي الوُصولِ إلى‌ مَنعِ تَوَلُّدِ القائِمِ أو قَتلِهِ، فَأَبَى اللَّهُ أن يَكشِفَ أمرَهُ لِواحِدٍ مِنهُم، إلّاأن يُتِمَّ نورَهُ ولَو كَرِهَ الكافِرونَ

Narrated that Abu Muhammad Imam Hasan Askari (عليه السلام) said, "The Banu Umayyah and the Banu Abbas put their swords against Us for two reasons:

The first reason is that they knew they had no right to the caliphate, so they feared Our claim to it and that it would settle in its true position.

The second reason is that they were informed of the repeated (Mutawatir) reports that the rule of the tyrants and oppressors will end upon the hand of the Qaim (عليه السلام) from among Us. And they did not doubt that they were among the tyrants and oppressors, so they made every effort in killing the family of the Messenger of Allah (صلى الله عليه وآله), and annihilating His progeny, hoping to prevent the birth of the Qaim (عليه السلام) or to kill Him. However, Allah refused to reveal His matter to any of them - except to perfect His light, even if the disbelievers detest it."

[Source: Mukhtasar Isbaath al-Rajah, al-Fadhl bin Shazaan, Hadith. 13 / Isbat al-Huda – Shaikh Hurr al-Amili, Vol. 5, Pg. 197]