Ser Lorimer was a lesser knight fighting for House Lannister during the War of the Five Kings, with Podrick Payne, member of a lesser branch of House Payne, serving as his squire. One night Lorimer got drunk and stole a ham, which he shared with Podrick. Lorimer was caught and the two were sentenced to be hanged. Lorimer was thus executed, while Podrick was pardoned by Lord Tywin Lannister because of his family name.
Podrick recounts his history with Lorimer to Brienne of Tarth. Podrick sympathetically says that Lorimer wasn't really a thief, he was just very hungry and drunk and wasn't thinking about what he was doing - clearly saddened that he ended up being executed for it.
In the books
In the A Song of Ice and Fire novels, Lorimer's story is quite similar. He's nicknamed "Lorimer the Belly" for being fat. He was a hedge knight serving Lord Leo Lefford. Podrick attached himself to him after his previous master, his kinsman Ser Cedric Payne, died fighting in the Riverlands. Lorimer was hanged as a thief after being found to have stolen a ham.
Lorimer and Podrick stole and ate the ham while in camp waiting for the Battle of the Green Fork, in the first novel. While this happened in Season 1 of the TV series, Podrick's introduction was pushed back to the beginning of Season 2. Therefore when he relates this story in Season 5's "High Sparrow", Podrick is explaining what he was doing "off-screen" in Season 1.