Baahubali stood against his kingdom to marry Devasena, so he left Mahishmati and seeing this as a threat, the newly appointed King Bhallaladeva wanted him dead. Kattappa killed Baahubali because it was his duty to secure the king of Mahishmati and he ia a slave of the throne as he said in Baahubali 1.