It is Allah Alone (Glorified and Exalted be He) Who fashions fetuses in wombs as He wills; males or females, complete or defective, etc. None but Allah (Exalted be He) can do this. Allah (Exalted be He) says:
He it is Who shapes you in the wombs as He wills. Lâ ilâha illa Huwa (none has the right to be worshipped but He), the All-Mighty, the All-Wise.
(Part No. 2; Page No. 172) Also Allah (Exalted be He) says:
To Allâh belongs the kingdom of the heavens and the earth. He creates what He wills. He bestows female (offspring) upon whom He wills, and bestows male (offspring) upon whom He wills.
Or He bestows both males and females, and He renders barren whom He wills. Verily, He is the All-Knower and is Able to do all things.
Allah (Exalted be He) says that He Alone has the kingdom of heaven and earth and creates whatever He wills. He shapes fetuses in wombs and makes them males or females, complete or defective, beautiful or ugly etc. None can do this but Allah Who has no partner. The claim that husbands, doctors, or philosophers can determine the gender of a fetus, is sheer falsehood. What a husband can do, is to be keen on having sexual intercourse at a time when fertilization is more likely to happen with hope that the wife will become pregnant. This hope may be achieved if Allah wills. But it may not be achieved either due to any prevention, e.g. Abnormal level of pus cells in the semen, sterility, or any other affliction as Allah may will. The law of causality is only effective if Allah wills it not by itself. In fact, fertilization is a natural act taken as a means to pregnancy but a person can only make but the outcome, the planning, and the determination remain with Allah's Will Alone. Whoever examines people's statements and deeds finds their vain exaggeration, false claims, and lies in words and actions due to their ignorance and excessive exaggeration of the findings of (Part No. 2; Page No. 173) modern sciences exceeding the limits of reliance on reasons. A wise person would distinguish between compelling things that take place by Allah's Will Alone and things divinely determined to take place at man's hand.May Allah grant us success. May peace and blessings be upon our Prophet Muhammad, his family, and Companions.