All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Artificial insemination has many forms; some of them are permitted, some are forbidden, while some others are uncertain.
The lawful way is taking a husband's sperm and fertilizing his wife's ovum in her womb without having physical contact. The other way is that the wife's ovum is fertilized with her husband's sperm out of her womb and then the fertilized ovum is implanted in the womb of his wife. The above two operations are lawful if there is any necessity.
As for taking the sperm of a man other than the husband, or ovum of a woman other than the wife, or taking a husband's sperm and his wife's ovum and implanting them in the womb of any woman, then all these practices are without any doubt, forbidden. Since this practice leads to the mixing of lineage which is similar to Zina; in addition, it lacks the meaning of tilth mentioned in the verse in which Allah Says (what means): {Your wives are a place of sowing of seed for you.} [Quran 2:223]
If pregnancy occurs through the latter ways the child will be considered as illegitimate and considering him as one’s own child is forbidden.
When a husband has two wives and one of them cannot conceive and, her ovum is fertilized by her husband's sperm and is implanted in another wife's womb, then this is a disputable matter.
For more benefit on artificial insemination, please refer to Fataawa 81889, 84063, 120049, 90358, 87640, and 87523.
Allah knows best.