He retired because he wasn't needed anymore after taking the fall for Harvey Dent. He told Gordon in the hospital dialogue, "The Batman wasn't needed anymore. We won." This is because the goal of Batman was to be a symbol that inspired people to fight Gotham's criminal and corrupt, as stated in Batman Begins. Since most of the cops were corrupt, Batman had to do this by vigilante means. Batman did this by waging war on organized crime—the root of the criminal and corrupt.



By the time of the events of The Dark Knight, he inspired both the copycat vigilantes and Harvey Dent to fight the criminal and corrupt. Bruce preferred the latter over the former as he told Alfred, "[the vigilantes] weren't what I had in mind when I wanted to inspire people". Bruce believes that Harvey was "the first legitimate ray of light in decades" and "the symbol of hope [Batman] could never be"; since Harvey was using legal means to fight the criminal and corrupt; and his prosecution managed to "lock up half of the cities criminals [without wearing a mask]", as Bruce prefaced it.



Since already 549 of the 1,000 criminals were now locked up—allowing what Dent called "18 months of clean streets" for the 549 criminals that comprised the whole mob (Lau, the mob's last money launder, when talking to the mobs, said, "everyone's money would be at stake", for the mob laundered all their money to him, but he surrendered all his clients to Dent)—Batman was soon not needed as the police could easily handle the remaining street criminals.



Also, The Dark Knight further explains the temporary nature of Batman: Natasha in the dinner scene mentions to Harvey Dent, "Gotham needs heroes like you—elected officials—not a man who thinks he is above the law." Bruce then agrees by saying, "Exactly. Who appointed the Batman?" But then Harvey, believing in vigilantism, answers, "We did—all of us who stood by and led scum take control of our city." But Natasha says, "But this is a democracy, Harvey." Harvey then says,



When their enemies were at the gates, the Romans would suspend democracy and appoint one man to protect the city. It was not considered an honor, it was considered a public service.



So, when an enemy, like organized crime or a terrorist, is attacking Gotham, there must be a suspension of democracy since only a vigilante like Batman can effectively beat it. But, Rachel rebuts, "Harvey, the last man to be appointed to protect the republic was named Caesar, and he never gave up his power." So, after Batman defeats organized crime, he must give up his power or else he will be corrupt. Harvey then agrees with this and says, "Okay, fine. You either die a hero, or you live long enough to see yourself become the villain." And since Batman indirectly defeated organized crime by having Harvey's prosecution lock up the whole mob, Bruce then honors what Harvey said by telling Rachel in the Penthouse party that he was going to retire soon.



But then the mob leaders used bail to get out of jail and hire Joker, who then caused Harvey to go on a killing spree. According to Gordon, because of Dent's murdering spree, "Harvey's prosecutions, everything he fought for...undone." The mayor warned Harvey that in 18 months of jail, the mob would try to use any dirt on Harvey to undo his prosecution during the appeal process. Thus, if the "criminals can get anything on [Harvey], they would be back on the streets." Batman reiterated the same thing to Dent after he caught him interrogating the insane man in the dark alley. Plus, according to Joker, if the people of Gotham find out about his murdering spree, they would "[lose] their minds". That would probably create freaks like the Joker. So, Batman had to sacrifice his reputation to keep the prosecution and to keep Gotham's sanity. Since no one knew of Harvey's crimes, the mob would fail at appeal and not leave jail. With the whole mob in jail, half the mob's money burned, mob bosses dead—leaving the mobsters vulnerable and eliminating financial incentives for police corruption—and the Joker captured, the remaining criminals on the streets would have trouble rebuilding the organized crime machine and would be arrested if they tried so. And with the Dent Act eliminating parole, the mob is locked up for good along with any additional criminals later arrested, thus deterring organized crime from bouncing back.



In conclusion, by inspiring Dent, the whole mob was jailed under his prosecution, then jailed for good—eliminating organized crime—under the Dent Act. Thus, Batman was no longer needed and Bruce could retire. Some viewers might note that The Dark Knight suggested Batman couldn't retire since Joker told Batman in their last encounter, "I think you and I are destined to [fight each other] forever." However, Batman rebutted him by saying "You'll be locked up in a padded cell forever." Joker then said, "Maybe we could share one." Thus, this suggests Joker would be locked up forever since he admitted to it. Also, some viewers might think Gordon saying "we will hunt him because he can take it" means Batman can't retire. Yet, in the The Dark Knight Rises hospital scene, Gordon seemed confused that Batman retired since he said, "We were in this together... then you were gone". He apparently misunderstood or forgot what Batman told him years ago, "You'll hunt me [...] because that's what needs to happen". Batman meant for Gordon to pursue him that night and thereafter so that the Batman could and would be viewed as a criminal not a crime fighter. Otherwise, Batman helping capture any remaining criminals would bring suspicion to the public and cops that Gordon framed Batman, would cause chase scenes on him allowing criminals to escape (like what happened with the stock heist chase), and would undermine Dent's martyring that inspired the public and cops to change for the better to fix the city. Edit