When I hear this question, I immediately think of "Papal Infallibility." Papal infallibility, according to Wikipedia, the source of all knowledge, is the belief in the Catholic Church that the "Pope is preserved from even the possibility of error when he solemnly declares or promulgates to the universal Church a dogmatic teaching on faith or morals as being contained in divine revelation, or at least being intimately connected to divine revelation." This protection is given by an action of the Holy Spirit. Interestingly enough, this was declared in 1870, at the First Vatican Council. An oversimplification of this statement would be that the Pope is always right, or put another way, the Pope is never wrong; because he is infallible (who would disagree with the Pope on _anything_ let alone a doctrinal exposition?).
Like the Catholics with Papal Infallibility, Mormons have a similar type of dogma with our Prophet. To make this easy, I'll call it Prophet Infallibility, or Prophetic Infallibility.
I have collected a group of statements about this subject after searching the internet and from my own personal library of books. They are in no particular order.
1. President Gordon B. Hinckley:
"It is the Lord who is directing this Church. You don't need to worry very much about Gordon Hinckley. The Lord is directing this work, and He won't let me or anyone else lead it astray. I am convinced of that. My only desire, and I hope your only desire, is to do that which the Lord would have us do."
(Fireside in Crawley, England, Aug. 26, 1995)
"Remember whose church this is. It carries the name of the Lord Jesus Christ, who stands as its head. His is the power to remove any who is found remiss in his duty or who is teaching that which is not in harmony with His divine will."
(Conference Report, Oct. 1992, pp 79-80)
2. President Wilford Woodruff:
"I say to Israel, the Lord will never permit me or any other man who stands as president of this church to lead you astray. It is not in the programme. It is not in the mind of God. If I were to attempt that, the Lord would remove me out of my place, as He will any other man who attempts to lead the children of men astray from the oracles of God and from their duty."
(Oct. 6, 1890; General Conference of the Church)
Comment: A little background on this statement seems appropriate. The United States Government passed the Edmunds-Tucker Act in 1887, the third major law passed against the practice of polygamy (1862 Merrill Anti-Bigamy Act and 1882 Edmunds Act are the other two); this one was enforced like the 1882 act, but unlike the 1862 act which was not. In May of 1890, Mormon Church v. United States came before the Supreme Court of the United State (136 U.S. 1), and the law was upheld escheating church property to the government (read: All church property over $50,000 was seized and owned by the government, not the church; with the church having to rent their own property from the government). Although it was promised that the temples (4 of them; Salt Lake, Manti, Logan, and St. George) would not be subject to this law, that was not the case. In 1893, personal property was returned to the church and in 1896, church real estate was finally returned (it took a while for Congress to believe the manifesto was legitimate).
Aside #1: This judgment helped propel the church into extreme financial difficulties because the members didn't want to pay tithing any more (the government would just seize it). These financial difficulties finally were done away with in 1907, under the administration of Joseph F. Smith.
In the midst of all this turmoil over polygamy and the Saints in vain trying to hold on to this practice against the wishes and laws of the U.S. Government, Wilford Woodruff presented what is known as the manifesto of 1890. This manifesto was presented to the church in General Conference (Oct 1890), and sustained there unanimously. In short, the manifesto abolished church practice of polygamy altogether. No longer would the church sanction, allow, or encourage plural marriages. Because Brigham Young and John Taylor had both lived their lives without giving in to the government, is it any wonder that the Saints would need an explanation why Wilford Woodruff would release the manifesto instead of fighting it and asking God to intervene on their behalf.
Aside #2: The manifesto, though accepted or "sustained" by the church, was a sore spot for some of the more fundamentalist members. The manifesto release actually marks the turning point for those currently in the FLDS (fundamentalist LDS) church; this is where they began. They believe Wilford Woodruff suspended polygamy without a revelation, thus since the command to revoke has never been given, they practice it still (covering their leadership and how that happened is a completely different subject). They also believe John Taylor received a revelation commanding the church never to suspend polygamy and that his son, John W. Taylor once a member of the LDS apostles, presented this to the twelve, and it was rejected by them (more fodder for the cannon in their opinion).
The next year, Nov. 14, 1891, President Woodruff said the following:
"The Lord showed me by vision and revelation exactly what would take place if we did not stop this practice. If we had not stopped it, you would have no use for Brother Merrill, for Brother Edlefsen, for Brother Roskelley, for Brother Leishman, or for any of the men in this temple at Logan; for all ordinances would be stopped throughout the land of Zion. Confusion would reign throughout Israel, and many men would be made prisoners. This trouble would have come upon the whole Church, and we should have been compelled to stop the practice."
"I saw exactly what would come to pass if there was not something done. I have had this spirit upon me for a long time. But I want to say that: I should have let all the temples go out of our hands; I should have gone to prison myself, and let every other man go there, had not the God of heaven commanded me to do what I did do."
It is no wonder that President Woodruff gave a speech telling the church that he was not leading them astray by removing the practice of plural marriage, he was in fact following the voice of the Lord and doing what needed to be done.
Another thing I find interesting about this is that this statement from President Woodruff is the most famous statement so structured to say that the prophet cannot lead the church astray. After this time, other presidents/prophets of the church have essentially reiterated what was said here in 1890. Because of the Reed Smoot hearings (1903-1907), the manifesto and some of President Woodruff's talk about it were put into the Doctrine and Covenants as Official Declaration 1. This is probably the main reason why this piece of "doctrine" is so widely known and quoted; it is in the Standard Works of the church whereas the other statements here are not.
I'll refer to this type of statement as the "Woodruff Doctrine" because it was declared by President Woodruff in a manner that was so clear, concise, and easy to understand, that nothing else really touches it as far as clarity. Additionally, all statements on this topic after this point in time seem to use this as a foundation for their statements. It is therefore apropos to use this statement as the foundation or qualifying statement for all future doctrines declared on this principle.
3. Elder Marion G. Romney recalled an experience with President Heber J. Grant:
"I remember years ago when I was a bishop I had President Grant talk to our ward. After the meeting, I drove him home ... When we got to his home I got out of the car and went up on the porch with him. Standing by me, he put his arm over my shoulder and said: 'My boy, you always keep your eye on the President of the Church, and if he ever tells you to do anything, and it is wrong, and you do it, the Lord will bless you for it.' Then with a twinkle in his eye, he said: 'But you don't need to worry. The Lord will never let his mouthpiece lead the people astray.'"
(Conference Report, Oct. 1960, pg. 78)
Comment: This is an addition to the statement by President Woodruff; not only will the prophet not lead the church astray, but if he happened to do it, you'll be blessed for following the council.
4. President Harold B. Lee, referring to President David O. McKay, said:
"We believe in a living prophet, seer, and revelator, and I bear you my solemn witness that we have a living prophet, seer, and revelator. We are not dependent only upon the revelations given in the past as contained in our standard works - as wonderful as they are - but ... we have a mouthpiece to whom God does and is revealing his mind and will. God will never permit him to lead us astray. As has been said, God would remove us out of our place if we should attempt to do it. You have no concern. Let the management and government of God, then, be with the Lord. Do not try to find fault with the management and affairs that pertain to him alone and by revelation through his prophet - his living prophet, his seer, and his revelator"
(Address given at BYU, July 8, 1968)
Comment: Again, he references the "Woodruff doctrine" and then off-handedly confirms what Elder Marion G. Romney said; i.e., that the members of the church need not worry about the council from the prophet; "you have no concern." Beyond that, he states that we shouldn't find fault with leaders and their council, which is definitely not a new statement, but he connects the statement with this prophet's infallibility.
5. President Joseph Fielding Smith said:
"I think there is one thing which we should have exceedingly clear in our minds. Neither the President of the Church, nor the First Presidency, nor the united voice of the First Presidency and the Twelve will ever lead the Saints astray or send forth counsel to the world that is contrary to the mind and will of the Lord."
(Conference Report, April 1972, pg. 99)
Comment: This is the great-nephew of the Prophet Joseph Smith, grandson of Hyrum Smith, and son of Joseph F. Smith. I do not know if this is the first time this type of statement was used; however, it really doesn't matter. This is an extension of the "Woodruff Doctrine" in that the First Presidency and the Quorum of the Twelve are included and together they will never lead the church astray. So we've mutated from just the prophet, to now everyone that is a "prophet, seer, and revelator" in the church (15 men normally - the First Presidency and Quorum of the Twelve).
6. President Joseph F. Smith said:
"If any man in that position should become unfaithful, God would remove him out of his place. I testify in the name of Israel's God that he will not suffer the head of the church, whom he has chosen to stand at the head, to transgress his law and apostatize; the moment he should take a course that would in time lead to it, God would take him away. Why? Because to suffer a wicked man to occupy that position would be to allow, as it were, the fountain to become corrupted, which is something He will never permit."
(Journal of Discourses 24:187-194; June 21, 1883)
Comment: This is a great quote, but lacks in only one thing: He wasn't the prophet when he said it, therefore President Woodruff's quote still trumps this one. Other than that, this quote still carries all of the same basic ideas as said in 1890, only without the ultimate authority of being said by the prophet himself.
7. Ezra Taft Benson said:
"Keep your eye on the prophet, for the Lord will never permit His prophet to lead this church astray."
(Conference Report, Oct. 1966, pg. 123)
8. Brigham Young said:
"The Lord Almighty leads this church, and he will never suffer you to be led astray if you are found doing your duty. You may go home and sleep as sweetly as a babe in its mother's arms, as to any danger of your leaders leading you astray, for if they should try to do so the Lord would quickly sweep them from the earth."
(Journal of Discourses 9:289)
Comment: This is the earliest reference I could find to this subject of a prophet's infallibility, or in this case any of the leaders of the Saints. The date on the talk by President Young is February 23, 1862. This is a pretty good quote by him. The talk by him was on the character of God and how some erroneous ideas about this had crept in amongst the Saints. The only reason this one isn't quoted very much is because it is just not as famous as the "Woodruff Doctrine" quote; other than that, I see this as being even more proof of the same idea, except it was expounded long before President Woodruff stated it.
9. Wilford Woodruff said:
"The Latter-Day Saints throughout Israel should understand that the first presidency of the church and the twelve apostles are led and guided by the inspiration of the Lord, and the Lord will not permit me, nor any other man, to lead the people astray."
(Collected Discourses 2:281-282; Oct. 25, 1891)
10. Joseph Smith said:
"This morning, I read German, and visited with a brother and sister from Michigan, who thought that 'a prophet is always a prophet;' but I told him that a prophet was a prophet only when he was acting as such."
(Teachings of the Prophet Joseph Smith, pg. 278; History of the Church Vol. 5:265; Feb. 8, 1843)
11. Doctrine and Covenants 1:38:
"What I the Lord have spoken, I have spoken, and I excuse not myself; and though the heavens and the earth pass away, my word shall not pass away, but shall all be fulfilled, whether by mine own voice or by the voice of my servants, it is the same."
Cross reference to D&C 84:44:
"For you shall live by every word that proceedeth forth from the mouth of God."
Cross reference to D&C 21:1,4:
"Behold, there shall be a record kept among you; and in it thou shalt be called a seer, a translator, a prophet, an apostle of Jesus Christ, an elder of the church through the will of God the Father, and the grace of your Lord Jesus Christ."
"Wherefore, meaning the church, thou shalt give heed unto all his words and commandments which he shall give unto you as he receiveth them, walking in all holiness before me."
Comment: Obviously this isn't exactly the same as the "Woodruff Doctrine," but it is pretty darn close. These scriptures say that the Lord speaks through servants (prophets are typically the servants He talks to: Amos 3:7), and these servants speak the word of God; therefore, the word of God needs to be followed. This all started with Joseph Smith, and now his successors hold this title of prophet.