Jesus warned them about persecution so that they won’t fall away. The Holy Spirit will guide us into all truth.
The Orthodox and Catholics claim that this means that the Holy Spirit will prevent the church as a whole from straying into heresy -- the Orthodox says this Holy Spirit preservation happens when there are Ecumenical Councils (meetings where every recognized branch of the church send representatives, to decide on doctrinal issues), while the Catholics say that, in addition to Ecumenical Councils, the Holy Spirit will prevent the Pope from making any doctrinal mistake when speaking Ex Cathedra (making official doctrinal teaching).
What does it mean, if we don’t believe in these (Catholic & Orthodox) things? We can’t say it means that the Holy Spirit preserves individual Christians from error, because that’s clearly not the case. Many of us have experienced the Holy Spirit’s guidance, but we have also seen in both ourselves and in others where mistakes happen and someone thinks that it was the Holy Spirit’s guidance when it wasn’t. I honestly don’t have a good reply to the Catholics and Orthodox about this issue.
At the end of the chapter, he goes back to the topic of persecution. “You will be scattered” and “In the world you have trouble and suffering, but take courage – I have conquered the world.”
Indeed, we can take courage -- it’s like watching a prerecorded game where we already know which side wins -- there may be trouble along the way, but the outcome is sure.