Why does O'Brien appear to befriend Winston? How could Winston end up caring for him, even though he tortures him?
From the very beginning, Winston is more smitten with O'Brien than he is with Julia. Ironically, he thinks Julia is the thoughtpolice (and she may have been), but he mistakenly sees O'Brien as a member of the Brotherhood.
The state has conditioned Winston to betray his own mother and the future mother of his potential children (Julia), in favor of the fatherland (Big Brother and O'Brien). Indeed the boot crushing force of the totalitarian government seduces rebels toward it. Winston abandons all that Julia helped him believe about Big Brother in pursuit of O'Brien. Winston ultimately trusts the father-figure (O'Brien) over the mother-figure (Julia), such is the conditioning of the Big Brother.
He mistakenly thinks Julia is a double agent and that O'Brien is not. Since the members of the Party are unable to speak or write to each other, they must conjecture (through physical appearances only) about one's allegiances. Throughout the novel, Winston will place more importance on love of O'Brien than of Julia: that O'Brien's abilility to see truth is more important than Julia's ability to give and receive love. He will mistakenly follow the Father(land) instead of the mother.
I believe that O'Brien appears to befriend Winston as a way of entrapping him. By pretending to be his friend, O'Brien can make sure that Winston commits thought crimes. O'Brien or the Party have probably figured out that Winston is a likely trouble maker. Because of that, it would be a good idea to get rid of him.
It has been shown that people taken hostage often end up sympathizing with their capturers. This is known as the "Stockholm Syndrome." I would expect that Winston could end up caring for O'Brien in this same way.