St. Paul, as an individual man was fallible. In writing those Epistles that are included in the Canon of Scripture he, like all other human authors of Scripture, was under the freely given influence and inspiration of the Holy Spirit using him as an active instrument so that they are truly the word of God.
This is a miracle of the intellectual order.
I agree with you that on normal occasions Paul was just as fallible as you or I, but when he was writing Scripture it was the words of God coming out of his pen.
Therefore when Paul, in his epistles, comments on or develops doctrine then it is no longer Paul's doctrine, but God's doctrine.