There's a handful of explanations as to why Federer loses games throughout his career...
1. He's a slow starter when playing against opponents he's not familiar with. Once he has about two or three matches with the player, the odds of beating Feds decreases considerably (it goes from 1% chance of winning to 0.00001%)
2. He's playing a guy who has the potential to get REALLY hot, although most of these players are headcases (Djokovic, Safin, Del Potro).
3. He's playing Rafa and he becomes a COMPLETE headcase.
4. Recently, he's starting to get old and he's lost some of the magic. He makes a lot more errors than he used to. Kind of like Tiger Woods now.
As for the other times when he loses for no reason, it's really no reason, just a fluke.