Leonard's Polaroids and tattoo system was developed during the Sammy Jankis case.While working on the case, Leonard had though occasionally about how he would handle such a situation, and came up with the Polaroid and tattoo placement ideas during this time. This gave him something to build on when he actually got the condition himself.
Leonard's memory problem is psychological, not neurological, and started after the trauma of his wife's rape.Trauma can induce amnesia, and more to the point, his memory of actual past events is unreliable, suggesting he's subconsciously rewriting events in his life to make himself not only his wife's avenger, but her eternal avenger. Lenny and wife get attacked, wife gets raped, and suddenly Lenny's got a problem — he's unable to accept that he couldn't protect her. As a result, he develops a psychologically based amnesia, so that he doesn't have to remember the attack at all. Eventually his wife tests him with insulin, no longer wanting to live with the hollowed-out human being she sees him as. He kills her, to maintain his "amnesia" to himself. After she dies, Lenny makes edits to things, perhaps at first based on pieces of hearsay or new "information" he gathers by beating the shit out of a few known associates of the bad guy. He eventually has marked enough of the police file up that his subconscious can reasonably convince his now-amnesiac conscious mind that there was a second attacker, and Lenny can vindicate himself and avenge his wife. Lenny's subconscious is fully aware that Teddy's playing him the entire time, but Lenny's conscious mind cannot become aware of this, because then the whole fantasy falls apart. Teddy's mistake is giving Leonard's subconscious that last little nudge — "I'm a John G." When his memory is challenged, he genuinely loses track of the memory — because his subconscious mind is keeping things consistent, because otherwise he has to face, directly, that he killed his wife to maintain his psychologically based amnesia, which was based on his inability to deal with her rape in the first place. When his mind sees a logical way to sidestep this issue — such as the motel clerk's clumsy attempt to double-room him — it grasps that opportunity and reinforces Lenny's belief that he's smart enough to compensate for the "amnesia". It also explains how he developed the note-and-tattoo solution — he actually has new memories, he just forgets that he can form new ones, recasting everything back as being about Sammy Jankis. (Hence, the Sammy Jankis tattoo's implication, that his subconscious wrote that as one of the first symptoms of his elaborate delusion, becomes even sadder.) Every now and then, though — little pieces of things come through, such as his musing that he must have burned his wife's stuff again and again. This is his subconscious achievement — taking revenge for his wife's rape and 'murder', because he cannot accept that he killed her with insulin due to his memory issues.
Leonard is mostly "with it", and deluded himself in the climax because he knew it would be best to kill TeddyTeddy is a crooked cop \ serial killer who is using Leonard to kill criminals. Most of Lenny's clues (including tattoos) were fed to him by Teddy (for example, over the phone Teddy pointed out evidence that John G is a drug dealer). Teddy will sometimes call Lenny and tell him "because of [convincing argument], this page is irrelevant now, so throw it out" when the next guy he wants killed doesn't fit with it (hence the missing pages). When Leonard killed Jimmy G, it didn't feel right to him. Through instinct, he either knew the guy wasn't John G, or through instinct he suspected that Teddy has been using him (this would be like if Jankis stopped grabbing the object that shocks him). Teddy says too much in the climax (either confident that Lenny likes the arrangement, or that he won't write it down in time), explaining they've killed multiple John Gs and that "we can go town-to-town killing John Gs forever". He also tells the story about how Jankis' wife is actually Lenny's; whether the story is true or not (probably is considering the memories of Lenny with the insulin needle), Teddy is using it to distract Lenny into thinking he's totally crazy long enough that he'll forget about Teddy's involvement (Teddy's only there in the first place to make sure Lenny gets back to the hotel without wandering around, and also to ensure Jimmy is dead). Lenny understands "I'm no killer", and he knows he wouldn't want to serial kill people for some strange form of vengeance ("you think I just want another puzzle to solve"). He concludes that Teddy is a crooked cop who has using him to kill criminals since his accident (might be the cop that was sent to investigate the accident in the first place). Knowing this, he has two options. One is to leave a note for himself explaining that Teddy is a serial killer; problem there is he would have a very hard time convincing people of this with his condition, plus, being a crooked cop, Teddy would easily get him killed or have him put away for his murders. Two is to burn the picture of him killing Jimmy G, give himself a clue that Teddy (conveniently a John G) is the killer. He feels it's best for Teddy to die (for his own survival, and to prevent further killings), and knows he'll never be able to pull the trigger unless motivated by this. There may be some holes in this WMG (Did Teddy feed the name John G? If so, was he that keen to kill drug dealing John Gs that he doesn't worry that he has the same name?! He probably didn't expect his licence-plate # to be looked up, but still), but it does make for a relatively happy ending, with the protagonist killing the serial killer.
They never found the real John GGiven the level of Teddy's trustworthiness as seen in the film, there's no good reason to believe he's being honest that the first "John G" they killed was the real rapist of Lenny's wife, or that Teddy even bothered to try. It's just as likely that he was scheming Lenny from the start, using him to tie the loose ends of his failed cases.
The SequelThe guy in Room #9 gets retrograde amnesia from the door attack, and seeks out Leonard for revenge!