What is the doctrinal basis for this practice?
It is in D&C 68:25–27, a revelation Joseph Smith received in November 1831, that this doctrine is outlined with the age of eight years old specified:
25 And again, inasmuch as parents have children in Zion, or in any of her stakes which are organized, that teach them not to understand the doctrine of repentance, faith in Christ the Son of the living God, and of baptism and the gift of the Holy Ghost by the laying on of the hands, when eight years old, the sin be upon the heads of the parents.
26 For this shall be a law unto the inhabitants of Zion, or in any of her stakes which are organized.
27 And their children shall be baptized for the remission of their sins when eight years old, and receive the laying on of the hands.
As for why this age in particular is the age of accountability, I don't think a specific justification is given in any Mormon scripture. But there is a discussion in Mormon scripture about why the baptism of young children in general is considered wrong. The reasoning is that young children cannot repent and do not need baptism. See, for instance, Moroni 8:9–12:
9 And after this manner did the Holy Ghost manifest the word of God unto me; wherefore, my beloved son, I know that it is solemn mockery before God, that ye should baptize little children.
10 Behold I say unto you that this thing shall ye teach—repentance and baptism unto those who are accountable and capable of committing sin; yea, teach parents that they must repent and be baptized, and humble themselves as their little children, and they shall all be saved with their little children.
11 And their little children need no repentance, neither baptism. Behold, baptism is unto repentance to the fulfilling the commandments unto the remission of sins.
12 But little children are alive in Christ, even from the foundation of the world; if not so, God is a partial God, and also a changeable God, and a respecter to persons; for how many little children have died without baptism!
Going back to the age of eight: In the Joseph Smith Translation for Genesis 17:11, a connection is made between circumcision at the age of eight days old and baptism at eight years old. In that verse, it states that circumcision was established to help those living at the time to understand that their children were not accountable to God before the age of eight:
11 And I will establish a covenant of circumcision with thee, and it shall be my covenant between me and thee, and thy seed after thee, in their generations; that thou mayest know forever that children are not accountable before me until they are eight years old.
The idea that circumcision was performed when a child was eight days old is established in scripture that is not exclusive to the LDS Church, both in the Old Testament (Genesis 21:4, Genesis 17:12) and in the New Testament (Luke 2:21, Luke 1:59).
Interestingly, there is also a scripture in the Doctrine and Covenants, D&C 84:28, that states that John the Baptist was ordained and baptized at the age of eight days old, on the same day he was circumcised:
28 For he was baptized while he was yet in his childhood, and was ordained by the angel of God at the time he was eight days old unto this power, to overthrow the kingdom of the Jews, and to make straight the way of the Lord before the face of his people, to prepare them for the coming of the Lord, in whose hand is given all power.