The details are a little fuzzy for me, but Theon eventually escapes on his own power. Ramsey marries (who he thinks is) Arya, but she is really an imposter; one of Sansa's old friends in Winterfell. Being the wife of Ramsey is one of the worst punishments imaginable, so "Arya" begs Theon to help her escape. Theon, who is scared to death at this point, doesn't want to, but he reluctantly helps her escape anyway. His chapters end at this point, so it's unclear what happens from there until the next book is released. George Martin did release a Theon, sneak preview chapter on his website. I'm not sure if it's still posted.