Short answer
Yes, when there is a need. The Hanafi school prefers that a woman be treated by a competent female doctor and a man by a male doctor, but when one is not available, or the needed skill is with the opposite sex, treatment is allowed. Only the part that needs examining should be uncovered, and the two should not be alone together. The four schools agree.
Permissible for need (hajah). A doctor may look at and touch only what the treatment requires. If a female doctor with the needed skill is available, she should treat a woman, and a husband, mahram or another woman should be present to avoid khalwa (being alone together).
The four schools agree on this.
Explanation
Treatment across genders has a basis in the Sunnah. Al-Rubayyi bint Mu'awwidh said the women used to go out with the Prophet ﷺ, giving water to the men, serving them and carrying the wounded back to Madinah. Imam al-Bukhari placed her report under the heading of whether a man may treat a woman and a woman a man.
The Hanafi texts give the method. The doctor may look at the place of illness because of the need. If possible, a woman should be taught to treat another woman. If not, everything except the affected area should be covered, and the doctor should lower his gaze from what he does not need to see. The same applies to a man treated by a female doctor or nurse.
In practice:
- ask for a female doctor for intimate examinations, smear tests, pregnancy care and childbirth where one is available
- ask for a chaperone; clinics in the US and UK will usually provide one
- do not delay urgent care while searching for a doctor of your own sex, since need comes first
- uncover only what is needed, and cover again when the examination is done
Talking therapy and consultations that do not uncover the awrah are lighter, but the rule against being alone together still applies; see seeing a therapist. The four schools agree on these principles. For the limits of the awrah, see awrah for men and women.
The evidence
Quran, Surah An-Noor 24:30
قُل لِّلْمُؤْمِنِينَ يَغُضُّوا۟ مِنْ أَبْصَٰرِهِمْ وَيَحْفَظُوا۟ فُرُوجَهُمْ ۚ ذَٰلِكَ أَزْكَىٰ لَهُمْ ۗ إِنَّ ٱللَّهَ خَبِيرٌۢ بِمَا يَصْنَعُونَ ﴿٣٠﴾
Tell the believing men to reduce [some] of their vision and guard their private parts. That is purer for them. Indeed, Allah is Acquainted with what they do.
Lowering the gaze applies in treatment too: the doctor looks only at what is needed.
Quran, Surah Al-Baqara 2:185
شَهْرُ رَمَضَانَ ٱلَّذِىٓ أُنزِلَ فِيهِ ٱلْقُرْءَانُ هُدًۭى لِّلنَّاسِ وَبَيِّنَٰتٍۢ مِّنَ ٱلْهُدَىٰ وَٱلْفُرْقَانِ ۚ فَمَن شَهِدَ مِنكُمُ ٱلشَّهْرَ فَلْيَصُمْهُ ۖ وَمَن كَانَ مَرِيضًا أَوْ عَلَىٰ سَفَرٍۢ فَعِدَّةٌۭ مِّنْ أَيَّامٍ أُخَرَ ۗ يُرِيدُ ٱللَّهُ بِكُمُ ٱلْيُسْرَ وَلَا يُرِيدُ بِكُمُ ٱلْعُسْرَ وَلِتُكْمِلُوا۟ ٱلْعِدَّةَ وَلِتُكَبِّرُوا۟ ٱللَّهَ عَلَىٰ مَا هَدَىٰكُمْ وَلَعَلَّكُمْ تَشْكُرُونَ ﴿١٨٥﴾
The month of Ramadhan [is that] in which was revealed the Qur'an, a guidance for the people and clear proofs of guidance and criterion. So whoever sights [the new moon of] the month, let him fast it; and whoever is ill or on a journey - then an equal number of other days. Allah intends for you ease and does not intend for you hardship and [wants] for you to complete the period and to glorify Allah for that [to] which He has guided you; and perhaps you will be grateful.
Need allows what would otherwise be avoided.
Sahih al-Bukhari 5679
Sahih... كنا نغزو مع رسول الله صلى الله عليه وسلم نسقي القوم ونخدمهم ...
"Al-Rubayyi said: We used to go out on campaigns with the Messenger of Allah, giving the people water, serving them and bringing the dead and wounded back to Madinah."
Women cared for wounded men in the Prophet's time, which shows treatment across genders is allowed for need.
Sahih al-Bukhari 5233
Sahih... لا يخلون رجل بامرأة إلا مع ذي محرم ...
"No man should be alone with a woman except when a mahram is with her."
Treatment should take place without seclusion.
Where the ruling is recorded
- al-Hidaya, Kitab al-Karahiyya, Fasl fi al-Wat wa al-Nazar wa al-Lams. The doctor may look at the place of illness for need, a woman should be taught to treat if possible, and the rest is covered.
- Radd al-Muhtar (Ibn Abidin), Kitab al-Hazr wa al-Ibahah, Fasl fi al-Nazar wa al-Mass. Details of looking and touching for treatment.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.