I remember this because Will and I watched the episode recently (we're working our way through Castle).
This is the third episode to deal with the 3XK (Triple X killer). The first episode was in season 3 and they run across the case and realize it's the same as a pattern from 4 years ago. The team works to solve the crime but 3XK does things like use a double to screw with time lines. He actually has everyone believing that he's the former cellmate of 3XK and they have him in a safe house.
Castle and Ryan go to the safe house and it's there that Castle figures out this guy Jerry is really the 3XK. Except he blurts it out and Jerry gets the drop on them and ties them up -- at some point Martha calls and Jerry gives the phone to Castle who says he's fine blah blah and ends the call with "I love you Mom". (or just I love you).
3XK does the evil villain thing and is either about to kill them when Beckett and the police swarm in or has left them.
Martha knew something was "terrible wrong" when Castle said I love you so she called Becket who sent everyone to the safe house.
Then in a later episode in season 4 a woman is killed with Ryan's gun. They spend a lot of time trying to figure out how the killer got his gun from Jerry and eventually they get a lead from the guy who had the gun that the guy who sold it to them, Jerry was going off to some state. But Castle doesn't believe it because it's too easy.
That episode is the one where the girl is the tutor and it turns out she's secretly involved with the guy she's tutoring - one of the sons of a Yakuza boss. The older brother killed the girl, but the love interest brother went into witness protection after offering to give evidence against his family.