The Book of Mormon teaches about the salvation of two special groups—those who had not the law and children. Abinadi refers to the former as those who did not have salvation declared unto them. Nephi said of them, the atonement satisfieth the demands of his justice upon all those who have not the law given to them (2 Nephi 9:26). These souls are innocent, like children, because they knew not the law of God. Nephi taught that when there is no law given there is no punishment; and where there is no punishment there is no condemnation (2 Nephi 9:25), for repentance is unto them that are under condemnation and under the curse of a broken law. And the first fruits of repentance is baptism (v. 24-25).
Therefore, those without the law do not need baptism. As Joseph Fielding Smith said, “There is no principle taught in the scriptures which is more clearly and definitely stated as to its nature and purpose than is the principle of baptism. There is no reason, except willful perversion of the word of the Lord, for anyone to misunderstand this principle. We are definitely and emphatically taught that baptism is for the remission of sins.” (The Way to Perfection, p. 196) One might not agree with this truth, quoting Jn 3:5, except a man be born of the water and of the Spirit, he cannot enter into the kingdom of God. But this was the word of the Lord to an individual and a nation which had the law given unto them.
We don’t often speak of this doctrine because our frame of reference is different. We know the law. We know the consequences of rebelling against the law. But how many millions of people have died without ever hearing the name of Jesus Christ, without ever being taught of a Messiah, without ever understanding the nature of the God who created them? Are they all doomed to suffer in spirit prison only to be resurrected to a telestial glory? Those innocent through ignorance will be resurrected according to the justice of God. Some will inherit a celestial glory (see DC 137:5-10 and Mosiah 15:24).
The scriptures go so far as to say that those without the law will come forth in the first resurrection, And then shall the heathen nations be redeemed, and they that knew no law shall have part in the first resurrection; and it shall be tolerable for them (DC 45:54). They will come forth in the first resurrection after those who are “the first fruits” (or those who come forth in the morning of the first resurrection). For the most part, they will inherit the terrestial kingdom and will be resurrected as “those who are Christ’s at his coming” (or those who come forth in the afternoon of the first resurrection). See also DC 76:71-73; 88:98-9; 137:7, Mosiah 15:24-25, Heb 5:2, and Mormon Doctrine, p. 640.
Joseph Fielding Smith
“We may be sure that the Lord would do all things according to the law of eternal justice and that he would not punish people who in ignorance sinned and violated his commandments. It is one of the most glorious principles of truth and justice that was ever revealed that men are to be punished according to their disobedience to divine commandments, but not when they have acted innocently in ignorance of those divine edicts.” (Answers To Gospel Questions, 4:77)