The fast food chain said that the burgers and buns don't rot because they become very dry in the cooking and toasting process:

"In the example of a McDonald’s hamburger, the patty loses water in the form of steam during the cooking process. The bun, of course, is made out of bread. Toasting it reduces the amount of moisture. This means that after preparation, the hamburger is fairly dry. When left out open in the room, there is further water loss as the humidity within most buildings is around 40%. So in the absence of moisture or high humidity, the hamburger simply dries out, rather than rot."