I was reading about the Thirty Years' War and noticed that Poland was allied against the Protestant states. I found this odd considering Germany's proximity and obvious influence of Protestantism and also Russia's closeness. Reflecting on this, I recalled how the late Pope John Paul II was from Poland as well. Did the Holy Roman Empire "invest" in Catholicism to spread in Poland as part of the Counter Reformation? I find it simply surprising that Catholicism has what appears to be such deep roots in Poland. Thanks !
Why Catholicism remained so strong in Poland? That is a solid book material and I'm afraid I could only give you a brief answer. I would rather choose a sociological approach and focus on modern history hoping that someone will complete my answer.
XVI-XVII century Poland was a multicultural and rather tolerant country. Freedom of belief strongly decreased the possibility of internal religious wars and granted relative stability. Of course some minor religious clashes still happened but never as a massive riots. Agreements made with Protestant groups in 1570 (Sandomierz Agreement) and more important in 1573 (Warsaw Confederation) granted freedom of religion. The second one is perceived as a proud proof of old Polish liberties - Poland was claimed to be a "safe shelter for heretics" and "a country without stakes".
Protestantism was not only present but remained a pretty strong political and cultural option. Calvinism influenced many of the Polish Noble - like the Great Marshall Jan Firlej and important Polish writers like Mikołaj Rej or Jan Andrzej Morsztyn, while the lutheranism was appreciated mostly by the middle class. Though Sigismund the Old opposed Protestantion movements, his successors, Sigismund Augustus and Henry of Valois granted rights to "blasphemers". In Poland existed Polish Brethrens - Polish Protestant church, whose members were later exiled for supporting Swedes during the "Deluge". Eastern Poland (today Belarussia and Ukraine) was dominantly orthodox. Still catholicism remained the strongest religion (most of the elected kings were catholics).
Poland didn't take an active role in the Thirty Years' War, because of political problems (war with Sweden, Muscovy, Ottomans, Zebrzydowski's and Cossacks' Uprising). Sigismund Vasa partially supported Habsburgs because strive for alliance with them (his wife was Anne of Austria from house of Habsburg). Sigismund III was a catholic himself and supported counter-reformation but never reallyy opposed protestants.
So why Poland stayed predominantly catholic? First of all protestantism never really influenced peasantry, which remained strongly catholic and conservative. Counter reformation in Poland had been very intense - especially Jesuits, who established many schools and influenced contemporary education. Post-Trident catholic intellectuals choose rather pacifist way to express their believes and point of view. The most useful weapon they used is the second factor of why Poland remained catholic - and you partially answered that question.
Protestantism was foreign and alien. In Poland it was connected with German influences and it's only strengthened the antagonisms between Polish catholicism and "foreign" protestantism. When we see which countries Poland fought with, there's almost no catholic nations - lutheran Sweden, orthodox Russia, muslim Ottomans. Another antagonism is visible sometimes on the social ladder - between catholic peasantry and protestant Nobles. The freedom of belief was progressively restricted.
During the birth of nations, Poland was partitioned and didn't exist. National identity had to remain despite loss of country. It was the Catholic Church the institution, which remained "national", a hub for Polish identity not influenced by foreign ideas. It is especially visible during the romanticism, when the idea of Poland as a Christ of nations was born. Poland like Jesus Christ had been sacrificed but one day will come back from dead. The idea of "nationalism" and "catholicism" become identical. Non-christian believes like Judaism were "safer" because Jews and Tatars were not perceived as Poles and often lived in its own communities.
The Polish Catholic Church was opressed especially by Russians and Germans, which only strengthen the opposition against opressors and bounds between society and Church. Pretty symbolical is the strike in Września in 1901-1902, where children refused to use German language during the religion lessons.
After the I World War about 2/3 of Poles were catholic.
However I think the strongest connections between Poles and catholicism were formed during the Second World War and soon after. Clergy was one of that social class, which were oppressed and extermined both by Soviets and Germans. Polish catholic Church had to work in conspiracy just like the higher education and cultural life. Many catholic priests died in concentration camps or gulags. New legends were born - like saint Maksymilian Kolbe, priest, who sacrificed his life for another prisoner. I think the monstrosities done during the II WW partially lead to reborn the Polish messianism.
Communist era in Poland was exactly hard for church, for it was clear that communists won't support the religious and national institution, because that would be against ideology. That way the Church was placed as the enemy of "people" and anti-communist. Many Poles, who opposited the real socialism, or just were anti-Soviet, sympathised with Polish Catholic Church, even if they weren't much religious. Catholicism wasn't only a religion - it was a way to say "no" to government. You can see how important it was thanks to Pope John Paul II. For foreigners our adoration toward "Polish Pope" may look funny or weird. I understand that and I often criticize it too, but you have to know, that it was not only a religious celebration but also a powerful strike to communist government. Another notable examples are Jerzy Popiełuszko - very popular priest, who criticized communists, beaten to death by Security Police or cardinal Stefan Wyszyński.
So answering your question. Catholicism is dominant in Poland mostly as a political result not because some "mystical" touch or special religiousness of Poles. Today the number of catholics in Poland is estimated between 90-95% of Poles, but I think it is an overestimation. Catholic Church is losing its previous position and sometimes is the object of criticism because of various scandals like financial and power abuses, ultra-conservatism or political allegiances.
I hope I answered your question. If you have further inquiries I - or someone, who knows history or English language better - will be eager to help. And sorry for any language mistakes.
Sources: Banaszak "Historia kościoła katolickiego" and various other materials.