Usul al-Kafi
Book 4:
The Book of Divine Proof

Chapter 60
A covenant from God

414. 3. Imam Jafar as-Sadiq (p): Imamate is a covenant from God, which is entrusted to a few who have been named. It is not for an Imam (p) to withhold it from one who follows him. God, the Blessed, the Sublime, revealed to Prophet Dawood (David) (p): Appoint a successor from your household, since it has already occurred in My Knowledge that I would not send forth any Prophet unless there is no successor from his household
Prophet Dawood (p) had many sons, and among them was a youth whose mother was with Prophet Dawood (p) and he loved her. Prophet Dawood (p) went to her when this revelation came to him, and said to her: God, to Whom belong Might and Majesty, has sent me a revelation, commanding me to appoint a successor from my household.
His Wife: Let it be my son.
Prophet Dawood (p): That is what I want.
But it had already occurred in the Knowledge of God, and had been determined therein that the successor should be Prophet Sulayman (Solomon) (p).
Thus, God revealed to Prophet Dawood (p): Do not hurry (in making this decision) until My Command comes to you. It was not long before two men approached Prophet Dawood (p) with a dispute amongst them, one person’s sheep ate the vines from the vineyard of the other person. God revealed to Prophet Dawood (p): Call both of your sons, and whoever correctly settles this legal dispute will be your successor. Hence, Prophet Dawood (p) called his sons and the two disputants presented their cases.
Prophet Sulayman (p): You, the owner of the vineyard, when did the sheep of this man come into your vineyard?
The Owner of the Vineyard: They came into the vineyard at night.
Prophet Sulayman (p) told the owner of the sheep: I pronounce judgment against you. You should give the owner of the vineyard, the off-springs of your sheep and their wool this year.
Prophet Dawood (p): Why did you not pronounce that all sheep be given to the owner of the vineyard? This is an established penalty among the learned people of Bani Israel, and the value of the vineyard is the same as that of the sheep.
Prophet Sulayman (p): The vineyard was not uprooted, and the sheep only ate what the vines bore, they will bear fruit (again) next year.
Then, God revealed to Prophet Dawood (p): The judgment in this case is as Sulayman (p) passed it. O Dawood, you want one thing and We want another.
Then Prophet Dawood (p) came to his wife and said: We wanted one thing and God wanted another, and only that which God, to Whom belong Might and Majesty, wants will come to pass. We are content with the command of God, and we submit to Him.
That is how the successors are chosen; it is not for them to take exception in the matter of appointing the successor, and to ignore its rightful recipient in favour of someone else.

415. 4. Imam Jafar as-Sadiq (p): Do you think that he who appoints a successor from among us appoints anyone he wishes? No, by God, indeed it is a covenant from the Prophet Muhammad (p) to one man (Imam (p)) after another, until it reaches the one who will complete it finally.