First it should be noted that Patriotism and Nationalism are two separate and distinct concepts. Patriotism is a virtue. Nationalism is defined as a devotion to the interests or culture of one’s nation. In extreme cases Nationalism is marked by a feeling of superiority over other countries and cultures. This is bad and can lead to sinful behaviors.
Patriotism or love of country is one of the obligatory forms of human and Christian charity towards the neighbor, coming in between the love of family and the love of mankind.
St. Thomas Aquinas, OP coupled together the two devotions, to parents and to country (Summa Theologica, 2a, 2ae, Q. 101). Dealing with the virtue of “pietas,” dutifulness, he writes: “The principles (or origins) of our being and governing are our parents and our country, which have given us birth and nourishment. Consequently man is debtor chiefly to his parents and his country, after God. Wherefore, just as it belongs to religion to give worship to God, so does it belong to “pietas,” in the second place, to give worship to one’s parents and one’s country.” Thus, unlike nationalism, patriotism comes within the sphere of virtue, duty, and moral obligation.
That this is and has always been the teaching of the Catholic Church may be gathered from the pronouncements of the Head of the Church as collected in such a work as La Patrie et la Paix. Textes pontificaux. Thus we find Pius X, in an address delivered in French to French pilgrims on April 19, 1909, saying in express terms: “Si le catholicisme etait ennemi de la patrie, il ne serait plus une religion divine” (if Catholicism were the enemy of the country, it would no longer be a divine religion). He went on to say (the translation is mine): Yes, it is worthy not only of love but of predilection that country (patrie) whose sacred name awakens in your mind the most cherished memories and makes quiver every fiber of your soul, that common country which has cradled you, to which you are bound by bonds of blood and by still nobler bonds of affection and tradition.”
Twenty years earlier, in January 1890, Pope Leo XIII, in his Encyclical Sapientiae Christianae set forth patriotism as a moral obligation based on natural law. “If,” writes the Pope, “the natural law bids us give the best of our affection and of our devotedness to our native land so that the good citizen does not hesitate to brave death for his country, much more is it the duty of Christians to be similarly affected to the Church.”