Click to see Spoiler:

It doesn't make quite as much sense in the sense of the HBO series, but in the book after Ned decides to send the girls home, he orders them to stay in their rooms till they leave. Sansa disobeys and runs to Cersei to tell her of Ned's plans, and Cersei is able to move more quickly than Ned, who still thinks he can play by his honorable rules. She's able to get the Gold Cloaks on her side because she had Sansa's advance warning and was able to take the girl hostage. Now, Ned may or may not have been taken by the Lannisters if Sansa hadn't revealed his plan to send them away, but it is possible that the girls, at least, might have gotten away. I tend to think not-Ned's far to naive when it comes to the motives of the other characters, and I tend to think that even without Sansa's betrayal Cersei would have outsmarted Ned just because she thinks in such devious ways.