Doctrine and Covenants 121:21 says that all generations of the sinners who reject the prophets shall not hold the priesthood. The way I understand was that no matter a parent’s choice, men are free to choose for themselves. Please explain.
While it is true that children have agency, it is also true that a parent’s choice has consequences for a several generations. There are individuals in my own family tree who have left their gospel roots, and that entire branch follows in the same tradition. The Book of Mormon gives a similar example of the Lamanites loosing the gospel (and of course the priesthood would be included in this) because their forefathers wholly turned away from it.
The verse you quoted reminds me of a similar promise given in the Old Testament when the Lord established the 10 commandments. He warned Israel not to make any graven image, because he visits “the iniquity of the fathers upon the children unto the third and fourth generation of them that hate me” (Exodus 20:5). I don’t think this is divine retribution as much as it is natural law. Parents who cling powerfully to a principle will find that same principle guiding grandchildren and great-grandchildren.
This works conversely as well. At the same time that God gave that warning, he also assured that he shows “mercy unto thousands of them that love me, and keep my commandments” (20:6). As a positive example, the happy Nephite society set up under Christ lasted until the fourth generation. The principles instilled in the 4th Nephi saints permeated the lives of their children and their grandchildren.