Presumably the show brought him back before the Purple Wedding so that his arc would come to a culmination at the end of Season 3 (i.e., getting back to King's Landing). In the book, he rescues Brienne from the bear before the Red Wedding, and then we don't see them until after the Purple Wedding; that'd be too many…