The position of imamate is bestowed only upon those who posses [specific] conditions, such as infallibility, abundant knowledge, etc., and no one except God has knowledge and awareness of these conditions and who truly possesses them. Thus, even before the creation of the Imams, their names and characteristicswere disseminated by God, and the Prophet (pbuh) had been notified. But, regarding the secret behind why imamatee, caliphate or prophethood is sometimes placed in the progeny of the previous prophet, it must be said that only God is fully aware of why, nonetheless, by considering two points, a fruitful response to the question is projected, to some degree:
The prophets, with their prophethood and perfections, won a place in the hearts of the people and gained special popularity among them. Also, when people love someone, they also love his righteous family members, and anyone who is in love, seeks the obedience of his [beloveds] requests. Therefore, the best people for imamate, succession or prophethood, are the offspring and descendants of that prophet, although, we do not consider this unconditional, rather there are some constraints and conditions, that include infallibility, being superior, etc., which are all necessary in an imam.
From among the offspring and descendants of the prophets, there have also been [some] unrighteous individuals, however, the impact of good and pure food (that has been obtained through means Allah swt is happy with) and a pure womb should not be forgotten in the training of competent descendents; even the role of inheritance (genetic issues), etc., shouldnt be ignored in the transfer of ethical qualities and competences. Therefore, the selection of an imam is based on merits and conditions, mentioned [above], and it is likely that hereditary factors do play a role in the transfer of these conditions and provide necessary grounds for it. It is for this same reason that a person of illegitimate birth is deprived of certain social positions such as imam of congregational prayer.
The proposed question, is indeed, a well-known allegation against Shias, that is, Shias believe imamatee is hereditary  ; while:
Shia belief is that conditions, including infallibility, being superior in various qualities, divine knowledge, etc., are necessary for an imam. These conditions are nothing but expressions of competencies, and, obviously, only God has knowledge of these competencies. Accordingly, the only way to determine an imam is through direct appointment from God, the Most High, and an introduction from the Prophet of God (pbuh) and the infallible imams. The Shias believe that, from the beginning, the names and characteristics of the Imams were known to God. Before they entered the World, through Gabriel, God informed the Prophet (pbuh) the names of all of them and the Prophet (pbuh) narrated their [total] number, order and names in several ahādīth.
After Imam Hassan (as), his brother Imam Hussain (as) became the Imam and after him the son of Imam Sajjād (as), while Mohammed ibn Hanafiyya, a brother of Imam Hussain (as), was still alive and was among the children of the Imams (as). Sometimes, rather than the older children, the younger children attained imamate, all of this indicating that imamate is an innate competence, that God has bestowed to those who deserved this prominent position .
If it has come in the sources of the [Muslim] sects that the Prophet (pbuh) confined caliphate to the Quraysh, is this the reason why Sunnis believe in a hereditary government for the Quraysh tribe?! And can you otherwise justify that caliphate is based on abilities, and that God has put the abilities in the Quraysh? Then, why is it that the same cannot be said about the Ahlulbayt?
Some say, the Quraysh was formed of numerous and different races, thus, this hadith isnt implying hereditarianism.
In response, we say, this deduction opposes the truth, because the Umayyids and Abbasids cited thishadith for the legitimacy of [their own] government and their own hereditary caliphate. On the strength of this, the government has been in the family of Quraish.
In sura Baqarah, verse 124, hereditary and genealogical rule, has not been completely denied, but has been denied specifically from the evil doers in the offspring and descendants of Abraham (pbuh). Hence, provided the offspring and descendants of Abraham (pbuh), and every other prophet, are not oppressors, whether oppression against God, or creation or the self, and possess the necessary competence, they can take the position of imamate and leaders of society. Obviously, the request of Moses (pbuh) was also based on the merit of his brother, Aaron. Is there a difference between Prophet [Mohammad] (pbuh) and other prophets, when their hereditary rule is based on merits and qualifications they bore, rather than just mere genealogy?
In continuation, it is necessary and essential to point out that although it must be said that the secret behind imamate, caliphate, or prophethood, is something that only God is fully aware of, even if we say all of these are dependant on competency and qualities, but it still seems correct to say:
The prophets, with their prophethood and their perfections, won a place in the hearts of the people and gained special popularity among them. Also, when people love someone, they also love his righteous family members, and anyone who is in love, seeks the obedience of his [beloveds] requests. Therefore, the best people for imamate, succession or prophethood, are the offspring and descendantsof the Prophet (pbuh), although, we do not consider this unconditional, rather there are someconstraints and conditions, that include infallibility, being superior, etc., which are all necessary in an imam.
From among the offspring and descendants of the prophets, there have also been [some] degenerate and unrighteous individuals, like the son of Prophet Noah (pbuh) and Jaffer Kadhāb, however, the impact of good and pure food (that has been obtained through halal means that Allah swt is happy with), and a pure wombshould not be forgotten in the training of competent descendents. The role of inheritance (genetic issues), etc., is also something that cannot be ignored in the transfer of ethical qualities and competences. The selection of an imam is based on merits and conditions, mentioned [above], therefore it is likely that hereditary factors do play a role in the transfer of these conditions and provide necessary grounds for it. It is for this same reason that a person of illegitimate birth is deprived of certain social positions such as being imam of congregational prayer, etc.
The reason that the criteria for imamate is merit and competency, and that the imams possessed these qualities in abundance, is that, as we know, the imams had more than one son, yet imamate only reached one of them. Moreover, the accusation against the Shias, of imamate being hereditary is raised and fuelled today by the Wahābīs. They say that the Shias believe that imamate is hereditary, while we see them harbouring support for and living under the states and governments control; the formation of which has been based on hereditary rule; such as the governments around the Persian Gulf. They also endorse governments, that have been formed based on inheritance and the source of their original establishment was based on inheritance, without any condition and merit in the ruler, to the extent that they have even been content with the rule of some of these rulers children; rulers whose original rule was based on being hereditary; like the government of the Umayyids and Abbasids.
So why is it that when it is becomes the Ahlulbayts (as) turn, they take the flag of opposition and attack the Shia, despite all the conditions that are apparent in the imams that the Shias believe in and that history has proven the validity of, so far as not a [single] weakness can be observed in them, even though they had and have many enemies?
 Ibn Hazm,; Al-Fisal; Vol. 4, p. 167. Baghdādī, Abdul Qāhar; U ṣ ūl Dīn , pp. 284-285. Nadwī, Abul Hassan, Ṣuratān Muta ḍ āditān , pp. 12-13.
 Majlesi, Muhammad Bāqir; Bihār al-Anwār; Vol. 26, p. 68; Darahya al-Trās al-Arabī, Beirut, Third Edition, 1403 AH. Sheikh Sadūq, Uyun Akhbār al-Reza, Ch. Ja an al-Re ḍ a fi Alāmāt Imām; p. 192; Manshūrāt Alami, Beirut, First Edition, 1404 AH. Al-Hurr al-Āmilī, Sheikh Muhammad; Al-Tanbīh min al-Burhān fi Tanziyeh al-Msūm an al-Sahw wa al-Nisyān.
 The stipulation of these conditions, from the Shia point of view, is itself the reason that they do not consider imamat as inheritable, but something that one must deserve and merit.
 Regarding this, The Reasons for Believing in Imamate and the Imams; Question 6421, Site Question: 7913 ; seems to be sufficient.
 For example, with that Ismail was the oldest son Imam Sadiq (as), Hazrat Mūsa ibn Jafar reached the position of wilāyat. And also that Mohammed was the oldest son of Imam Ali Naqi (as), however his brother, Hasan, got the position of wilāyat. Qummi, Sheikh Abbas; Muntahī al-Amāl; Vol. 2, pp. 294, 687-688; Nashr Hijrat, Qom, 1377 Shamsi. Also see: Al-Hāmi, Dāwūd; Iran wa Islam; p. 698-697; Daftar Majaleh Maktab Islam, Qom, 1374 Shamsi.
 The Prophet of God (pbuh) said: This World will not come to an end until twelve caliphs, all of whom are from the Quraysh, have ruled it. Al-Bukhari, Mohammad; Sahih al-Bukhari; Vol. 2, p. 3, Kitāb al-Amārh, Ch. An-Nas tab li Quraysh wa al-Khalāfh li Quraysh.
 وَإِذِ ابْتَلَى إِبْرَاهِیمَ رَبُّهُ بِکَلِمَاتٍ فَأَتَمَّهُنَّ قَالَ إِنِّی جَاعِلُکَ لِلنَّاسِ إِمَامًا قَالَ وَمِن ذُرِّیَّتِی قَالَ لاَ یَنَالُ عَهْدِی الظَّالِمِینَ And when his Lord tested Abraham with certain words, and he fulfilled them, He said, I am making you the Imam of mankind. Said he, And from among my descendants? He said, [yes, if they are worthy of it], My pledge does not extend to the unjust (2:124).
 This is an inaccurate way of putting it, because there is an essential difference between hereditary rule, and caliphate of the prophets and imams. And so it is that in hereditary governments, God has no role in determining the king and the competence of a person is not the criteria.
 وَٱجْعَل لِّى وَزِیرًا مِّنْ أَهْلِى هٰرُونَ أَخِى Appoint for me a minister from my family, Aaron, my brother (20:29-30).
 أَمْ یَحْسُدُونَ ٱلنَّاسَ عَلَىٰ مَا ءَاتَىٰهُمُ ٱللَّهُ مِن فَضْلِهِۦ فَقَدْ ءَاتَیْنَا ءَالَ إِبْرٰهِیمَ ٱلْکِتٰبَ وَٱلْحِکْمَةَ وَءَاتَیْنٰهُم مُّلْکًا عَظِیمًا Or do they envy the people for what Allah has given them out of His grace? We have certainly given the progeny of Abraham the Book and wisdom, and We have given them a great sovereigity (4:53).
 Rizwani, Ali Asghar; Shia Shanāsī wa Pāsukh be Shubahāt; Vol. 2, p. 495-499.
 Part of the physical and mental health of children is inherited by the children through transfer from their parents. Islam recommends, at the time of marriage and cohabitation, both partners should carefully consider each others attributes, and emotional and physical characteristics, so that the fruit of their life together is a healthy child. The Prophet (pbuh) said: choose an appropriate place for your sperm, because the roots (genes) are factors are passed on [to the children]. The holy Prophet (pbuh) has stated elsewhere: abstain from plants that grow between litter, thorns and weeds. When asked: O Prophet of God, what are the grass and plants? He said: A beautiful woman who is nurtured in an inferior and polluted family environment. The Etiquette of Child Conception ; Question 1057, Site Question: 1122. Hence, to prevent physical and psychological disorders of children, genetic and blood testing is essential.
 For more information see: Mans Nature and its Effects on Ones Behavior ; Question 692, Site Question: 739.
human nature and its effects on human behavior, Q 692 (Page: 739).
 For more information see: The Imam of Congregational Prayers Being of Legitimate Birth and the Reason behind It ; Question 1957, Site Question: 1982.