George obviously did not have the legal right to kill Lennie at the end of the story, but he seems to have the moral right to do so. Most readers probably feel that this is a satisfactory and appropriate ending. None of the men seem terribly concerned about legality. All of them are hunting for Lennie with the intention of lynching him for murdering Curley's wife. They do not seem apprehensive about any legal repercussions if they do what they intend to do--which is not just to kill Lennie but to torture him before they finish him off. The local law enforcement officials would probably do nothing about the incident. Things were different in the 1930s. Lynchings were not uncommon, even in California.
George is killing Lennie to save him from suffering much worse treatment by the mob led by the sadistic Curley. Lennie's death by a single shot to the back of his head is sudden, unexpected, and painless. So Lennie seems justified in shooting him. He has no alternative. He can't turn Lennie over to any asylum because the mob is closing in on them. He doesn't have the legal right to have Lennie committed anyway, since he isn't a relative.
George is assuming a responsibility which he believes is his alone. He is not especially concerned about being legally punished for killing his friend because everybody thinks Carlson's Luger was stolen by Lennie, and therefore they will all assume--and testify, if necessary--that George took the gun away and killed Lennie in self-defense. Both Slim and Carlson hand George his alibi without his even bothering to invent one.
But Carlson was standing over George. "How'd you do it?" he asked.
"I just done it," George said tiredly.
"Did he have my gun?"
"Yeah. He had your gun."
"An' you got it away from him and you took it an' you killed him?"
"Yeah. Tha's how."
Slim twitched George's elbow. "Come on, George. Me an' you'll go in an' get a drink."