Didn't see episode until today, caught a glimpse of the butthurt on reddit so I knew someone was going to die. Basic law of TV to put this sort of thing at the end of the episode so that kind of ruined the shock for me. Still, it was pretty brutal.
My interpretation was that Bolton was in on it. Frey said something about a wedding gift to Bolton, doesn't Robb's death mean Bolton moves up in rank so he can lead the armies/ become king of something? And he now has a Frey wife so that house gets some glory too.
Will be interesting to see Brienne's reaction considering how she and Jamie have been getting along.