It was more detailed in the books. Basically, this group that captured Jaime was on Bolton's side (and Bolton's were on Robb's ), they were major pricks tho, like in the show. Their commander suspects that Roose might have some deal with Lannisters, so he orders to cut Jaime's hand, hoping that the blame will fall on Roose (= destroying his relations with Lannisters). Then Roose comes and promises to free Jaime if he'll forget about this 'unfortunate' episode.

He frees him, but he already has a deal with Lannisters that Jaime doesn't know about. (=Red Wedding).