You are not alone in wondering what in the world does this have to do with infertility??? No, as far as I know this does not cause infertiliy. But it becomes an issue due to the collection of semen. In order to do this in most cases one would have to indulge in the act of masturbation
Throughout the centuries the majority of scholars have ruled that masturbation is haram (forbidden). Even with such a ruling there is no set punishment for the act itself. The main argument of making it haram is
(The Believers)Who abstain from sex
Except with those joined to them in the marriage bond or (the captives) whom their right hands possess -
for (in their case) they are free from blame
It is stated that the only halal time to use the sexual organ is outlined in this ayat. That any use of the organ in any other way sexually is to transgress the boundaries given in Qur'an making one a transgressor.
But those whose desires exceed those limits are transgressors
It is important to note at this point, this ruling does not apply when masturbation involves ones wife. Meaning that if a wife is sexually gratifying her husband in such a way it is permissible. Because the man has a right to recieve enjoyment from his wife, be it her hand or other parts of her body.
Now while I personally feel this happens to be a very minute issue of Infertility, many muslims point to this when a couple seeks treatment. They neglect that there is a basic ideal within Islam that if one must do something that is normally haram by necessity than it becomes permissible. We see this point very clearly in the forbidance of certain foods, but Allah has also stated along side the prohibition
...But if one is forced by necessity without willful disobedience nor transgressing due limits -
then is he guiltless. For God is Oft-forgiving Most Merciful.
But (even so) if a person is forced by necessity without willful disobedience nor transgressing due limits -
thy Lord is Oft-forgiving Most Merciful.
This ideal is not limited to only that of food, but is an accepted general rule within shariah (Islamic Law). This general acceptance can also be seen in the actions of Umar (r.a.) who lifted the punishment for theft in the time of famine. This same point has been brought into discussion by Abul Ebrahim, which he states;
"But the question before us now is whether it would be forbidden under Islamic law to masturbate in order to obtain the semen so as to have one's wife impregnated with it through artificial insemination. Support of permitting it should be argued on the basis that engaging in the act is not to derive pleasure but, rather, to obtain semen for the specific purpose of trying to solve the problem of infertility. Permission would come from the purpose-oriented concept of the higher goals contained in the juristic principle that 'necessity renders the forbidden permissible'"(1)
What a couple could choose to do is have the wife "help" the husband collect the semen. Or keep in mind that Allah (swt) does not want Islam to be a hardship for us, but rather an easement. And He is Oft forgiving and Most Merciful to those commited by necessity.
(2) All Qur'anic Translations by Yusuf Ali