But Locke was one of the few people who understood that Naomi was working for Widdemore and was really there to help kill everyone on the Island. So by killing her he was, in fact, trying to save everyone.