The main reason behind this is Megatron's own ability to perceive the attributes of StarScream . Perhaps he sees a little of himself in StarScream , if not the physical part, at least the "cunning part" definitely. This prompts him to re consider his decision of killing StarScream. For he thinks, StarScream may inadvertently come up with a useful idea to demolish the autobots , which Megatron then can use at his own discretion.
Having said that, Megatron is in a dilemma, he is constantly toying with the idea of either having StarScream terminated or banished , but he seems just not able to make up his mind, due to his past association with StarScream. Also, due to the same reason he may think, that StarScream will never be able to outwit him.