katappa killed bahubali because bahubali understood that he would be killed and katappa too would be killed. so to save his sons life and to show that he supported bhallaldev... bahubali himself instructed katappa to kill him.... for the future of the kingdom
Bhahubali was going to be killed anyways, but rather than be killed by enemies, he asked katappa to kill him so that he could have an honorable death. Just like Dumbledore asked Snape to do for Draco.
Bahubali denied kharra to katappa and katappa was annoyed that the bahubali even shared his meal with him but denied just kharra. Katappa thought this is real bahuballi while on other hand when demanded bhallaldev who never liked to share meal, gave his complete kharra. Bhallaldev then demanded as a token of friendship to kill bahubali so in height of confusion, he killed. Katappa regreated it later when he found bhallaldev kharra was expired while bahubali denied him kharra for same reason
When bahubali meets anuska shetty, a situation is created that bhallaldeva also likes her, so he urges to sivgami, then condition aries that both the brothers liked same girl and again shivgami keep a options before the two men to chose either the girl or kingdom,so bahubali choose the girl
Pingaladeva & Bhallaladeva could not stand Bahubali's popularity and so they order Kattappa who was a servant of the Kingdom to kill Bahubali. Kattappa being a slave had no choice but obey the royal order.