No, there is no contradiction. The earlier statements were simply overgeneralized and misleading. Cardinal Ratzinger is simply adumbrating the solution to a severe tension that exists in pre-Vatican II thought.
Let me explain what I mean by way of a concrete example. The Church has long believed and taught that (among others) the Orthodox retain valid sacraments – among them, baptism. So let us suppose that an Orthodox baby is baptized, and then dies shortly after. The baptism has washed away all stain of original sin and filled the child with sanctifying grace; and the child, of course, had no personal sin of his own. We therefore believe that such a baby is saved and would go to Heaven. Ah, but wait – extra ecclesiam, we are told dogmatically, nulla salus! No salvation outside the Church!
So it seems we must admit that either (1) such a baby, despite being validly baptized and having no original or personal sin, will for some reason be condemned by God to Hell, or else (2) he is in some way inside the Church. Since we reject position (1), we conclude that in fact the graces which God makes available through his Church have, in some measure, been operating through the Orthodox. This becomes even more apparent when we consider that the Eucharist is valid in Orthodox churches – the quintessential sacrament of redemption and unity.
It is true, then, as Pius IX said, that “all who want to belong to the true and only Church of Christ must honor and obey” the Pope. But this does not answer the broader question of whether any of the graces of the Church are present elsewhere in the world. And we know that they are. To give still another example, traditional Catholics are sometimes found saying that the Protestant sects were founded by Satan do his diabolical work and no good fruit can come of that evil seed. Yet we know by experience that many people are brought from paganism or unbelief to faith in Christ through the evangelism of Protestants – and no small share of those wind up as converts to Catholicism itself. If we believe that preaching Christ and baptizing the heathen is a work of Christ’s Church, which we do, then we must confess that Protestants are engaged in the Church’s work, however imperfectly.
That is what it means to say, as did Lumen Gentium, that although Christ’s Church “subsists in the Catholic Church,” nevertheless “many elements of sanctification and of truth are found outside of its visible structure.” To be sure, the farther one gets from the Catholic Church the less good and sanctification one finds, and the more error and evil is mixed in with it. But the “Fortress Catholicism” mentality which was sometimes present in older writers and preachers, according to which everything inside the Catholic Church is good and everything outside is uniformly evil or at best “secular,” cannot stand up to the truth that many of the things we find outside the Catholic Church – valid baptisms, preaching the name of Christ, encouraging sound morals according to the natural law, even the sacrament of the Holy Eucharist – are good, and are among the graces that God has bestowed on mankind flowing through his Church.
The old statements you have found about “belonging” to the Church, although true in the limited sense in which they are written, do not exhaust the discussion about how far the work and sanctification of the Church is or can be operative outside the ecclesial walls of the Catholic Church – to which, it must be re-emphasized, God does indeed want to draw all his faithful. Resolving this tension, and especially doing so while avoiding indifferentism, is not easy, and if there is one thing we can be sure of it is that the Church has not said everything on the matter that there is to be said.