As a king, Rama was bound to maintain Chaturvarnya. It was his duty therefore to kill Shambuka, the Shudra, who had transgressed his class and wanted to be a Brahmin. This is the reason why Rama killed Shambuka.
Shambuka story is said to be an interpolation (later addition) in Valmiki Ramayana.