This is what happened.
Rama, the performer of unblemished deeds, spoke these words. Hearing them, with his face hanging downwards. he replied in these words, ‘I have been born in the womb of a shudra and have resorted to these fierce austerities. O Rama! O immediately illustrious one! I wish to go to heaven in my own physical body, O king! I do not utter a falsehood. I wish to conquer the world of the gods. O Kakutstha! Know me to be a shudra. My name is Shambuka.’ Hearing the shudra’s words, Raghava unsheathed his sparkling sword, extremely beautiful in its radiance, from its scabbard and severed his head.
Ramayana, Uttara Kanda, chapter 7(67) translated by Bibek Debroy
The part of Ramayana that talks of Shambuka is considered by most scholars as an interpolation. Most probably Valmiki never wrote that story.
However, Rama’s action is justified. Shambuka was doing Tapas in order to gain control ofconquer lower heavensheaven. Rama killed Shambuka to stop him from gaining control ofconquering lower heaven and not because he was a shudra.No No jiva is allowed to conquer the lower heaven.
Hindu scripture is replete with stories about Asuras conquering heaven and killed by God as a result.
A similar story is there in Shiva Puarana. Lord Shiva killed his son Jalandhara who also did tapas to gain control overconquer lower heaven.
The Shambuka story is not an unusual story.