To add to FF’s response above, consider when and how “infallibility” in teaching would occur.
A matter comes before the Holy Father. Something that is of great import to the entire Church. It could be stem cell research, it could be new methods to help couples conceive, it could be…Whatever…
Now these issues do not come out of the blue, nor does the Holy Father “dream these up”. They are most often things that have already been discussed for some time - perhaps beginning even before he was elected pope. So generally the Holy Father has already heard of the issue and given it some thought AND discussed it with others - his brother bishops, members of pertinant committees, other curial officers, etc…
The Holy Father then prays. In fact He prays constantly - for the guidance of the Holy Spirit. He prays for Humility, that his personal views do not interfere with the will of the Holy Spirit,. He prays for Understanding that he will be able to rightly discern all the aspects of a given issue. He prays for Clarity that he might be able to properly teach and communicate the Will of the Holy Spirit. He then places all his faith in God and waits for God to make clear what His will is for His children.
Once the answer is clear, the Holy Father turns again to his advisors who, with him, develop the teaching to be promulgated, write it down, review it, adjust it and finally publish it.
Now - I’ve laid out a fairly linear flow above, but of course it isn’t so linear as I have expressed it. Much of this takes place in overlapping fashon. Issues overlapping one another, ideas and debate go up and down the heirachy, as well as around and around within the Church universal.
but ultimately to try to answer your question of how this is infused. It is infused at his election to and acceptance of the Chair of Peter. The Spirit Guided conclave of Cardinals, elects the man whom the Holy Spirit wishes. Once elected the Spirit comes and protects him.