There are really many reasons why George kills Lennie. It is often explained that this is a "mercy killing." George supposedly wants to save Lennie from the lynch mob, who will make his death as painful as possible, whereas George knows how to kill him instantly and painlessly with Carlson's Luger because Carlson has demonstrated how to do this with Candy's dog. But this explanation is an oversimplification. George has realized that Lennie is becoming a menace to society. Twice the mentally retarded giant has been involved in what could be interpreted as rape attempts, once in Weed and once with Curley's wife in the barn. George can't be watching Lennie all the time, and Lennie gets into trouble when he isn't being watched. Then he lies about it.
George realizes that Lennie is morphing into a monster who attacks young girls and is capable of killing them if they struggle. But George is getting fed up with being a caretaker, as he states repeatedly throughout the book. Furthermore, George feels responsible for the death of Curley's wife. If George hadn't protected Lennie in Weed, Lennie would never have encountered Curley's wife. George is not only morally responsible, but he believes he could be considered an accessory after the fact to that girl's murder. He is also afraid the lynch mob might turn on him because he and Lennie are so closely associated. Just before the mob leaves the ranch to hunt for Lennie,
...Curley called, "You George! You stick with us so we don't think you had nothin' to do with this."
Curley suspects that George knows where Lennie went to hide. That in itself could make George appear guilty as an accessory. If someone commits a murder and you tell him where to go and hide and you say you don't know where he is hiding--then that makes you appear partly responsible for the murder. In the first chapter George instructed Lennie about where to come and hide if he got into trouble. That indicates that George expected Lennie to commit some serious offense, which could be interpreted to make George an accessory before and after the fact. How would anyone know that George had told Lennie where to hide if he got into trouble? Lennie would probably tell them.
George would have gotten killed by the mob in Weed, too, if they had been able to catch him and Lennie--or him alone. George is kind enough to make some sacrifices for Lennie and Aunt Clara, but he is not idealistic enough to become a martyr. George is very angry at Lennie and fears for his own life. He wants to distance himself from this trouble-maker. He cares enough to want to execute Lennie by himself, but he believes, as do all the men in the lynch mob, that Lennie must die. If he left Lennie to the lynch mob, they would kill him in a horrible manner. If he could manage to help Lennie to escape and then turned him over to the law, Lennie would get convicted of murder and executed by hanging (which was the legal method of execution in California at the time). Lennie is really only guilty of accidental manslaughter, but he would be totally incapable of explaining that to anyone. If George helped Lennie escape and didn't turn him over to the law, he could expect repetitions of what happened with the girl in Weed and with Curley's wife in the barn.
The fact that George steals Carlson's Luger in the bunkhouse shows that he has made up his mind to kill Lennie by that point. What prompted his decision was the sight of the dead girl in the barn.
Curley's wife lay with a half-covering of yellow hay. And the meanness and the plannings and the discontent and the ache for attention were all gone from her face. She was very pretty and simple, and her face was sweet and young. Now her rouged cheeks and her reddened lips made her seem alive and sleeping very lightly. The curls, tiny little sausages, were spread on the hay behind her head, and her lips were parted.