All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
First of all, you should know that superiority in Islam is based on righteousness. Allaah Says (what means): {Indeed, the most noble of you in the sight of Allaah is the most righteous of you.}[Quran 49:13]. The characteristic of being a fertile woman, by itself, does not prove her superiority, and being barren does not prove her inferiority. Therefore, she should not be blamed for this reason since it is not her choice as she was born as such. As for the prophetic narrations that encourage marrying a fertile woman, then this is in order to achieve some religious benefits, like having many children and the like. The Prophet said: "Marry the loving and prolific women, as I will outnumber the nations by you [by your abundant number]." [Ahmad] Such narrations do not necessarily mean that a woman who is not prolific is not virtuous.
However, we do not know any religious evidence that prohibits marrying a barren person, be it a man or a woman; rather, the religious texts that encourage marriage are general. In addition to this, being chaste is an additional benefit in marriage, and probably, every man and woman seek to achieve chastity.
As for the narration reported by Imaam Ahmad Ma'qil Ibn Yasaar narrated that a man came to the Prophet and said: “I have found a woman of honourable lineage and beauty, but she does not give birth to children. Should I marry her? He said: “No”. He [the man] later returned again, and he prohibited him. The man returned for the third time, and he (the Prophet ) said: “Marry women who are loving and very prolific, for I shall outnumber the nations (on the Day of Resurrection) by you [by your abundant number]." This narration advocates what is better, and highlights the benefit of multiplying the progeny, as we mentioned above.
'Umar married a barren woman from Bani Makhzoom and then he divorced her and said: "I do not sleep with women only for enjoyment; if they do not give birth, I do not need them."
'Umar practiced a permissible right to divorce, just like a woman has the right to ask for divorce if her husband is barren, because both of them need to be blessed with children. The ruling here applies to both the husband and the wife.