In researching dogmas I’ve found they are defined against the background of heresy. Vatican I for instance declared papal infallibility probably in response to Protestantism and division. The Assumption of the Blessed Virgin Mary was proclaimed dogmatically to affirm the dignity and destiny of humans against the abuse of the Nazis. That is what I read anyway.
Was there any heresy or tendency that contributed to the proclamation as dogma the immaculate conception? Was this dogma proclaimed by the Pope meant to guard against heresy?
Well, yes and no.
No in so far as that it wasn’t the purpose of Pius IX’s declaration. According to his letter, it was to show Mary honor, and in response to the request of the faithful. It wasn’t explicitly in response to any formal heresy at the time.
But, by the guidance of the Holy Spirit, it
was actually an antidote to some of the philosophies which were coming into the fray at that time. Philosophers, like Nietzsche and Marx etc…were introducing the idea there was no such thing as sin. Every human being was basically an Immaculate Conception according to them. (Of course, they didn’t call it that) The dogma of the IC was the Church’s way of guarding the truth that there is such a thing as sin, and there’s only
one human person who’s ever been conceived without it, (besides Adam and Eve) and that was
only through the grace of her Son and Savior, not her own power. So in that sense it did counter a heresy. That just wasn’t its original purpose, at least not the Pope’s original purpose.
I feel like I’m not explaining this well. I hope it made some sense.

I just can’t seem to put it in the right words. Fulton Sheen actually talks about exactly this in his book, “The World’s First Love” I really liked how he explained it. He said basically what I just said but only much better of course.

I used to wonder this exact same question, and that book really shed a lot of light on the Immaculate Conception for me. So far it’s one of my favorite books by him.