Is Prayer Valid If Hair Shows Through Hijab Gaps in the Hijab?
Question

When I pray, I always try to hide my hair by wearing a prayer suit, but sometimes I touch the back of my head and feel that my hair is sticking out like thorns. In this case, is my prayer valid or invalid?
Praise be to Allah.Importance of Covering the `Awrah in Prayer
Covering the `Awrah is a condition of prayer being valid according to the majority of scholars, in the case of both men and women.
What is required of the worshipper is to take proper precautions regarding his prayer before starting to pray. So he should wear something that he is certain will cover his `Awrah, and he should not wear anything that he fears may show any part of his `Awrah whilst he is praying .
A woman’s hair is `Awrah and she must cover it; this applies to all of her body except the face and hands. Hence she must make sure to cover her hair with a headcover in such a way that none of her hair sticks out from it. It should not be so thin that it shows what is beneath it, or have large openings through which the hair may protrude.
It is soundly narrated in the Hadith of `Aishah that the Prophet (blessings and peace of Allah be upon him) said: “Allah does not accept the prayer of a woman who menstruates [i.e., a woman of childbearing age] except if she is wearing a headcover.” (Narrated by Abu Dawud (546); classed as authentic by Al-Albani in Sahih Sunan Abu Dawud, 596)
Shaykh Al-Islam Ibn Taymiyah (may Allah have mercy on him) said: If a woman prays on her own, she is enjoined to cover her head… The one who wants to pray may be enjoined to cover something that it is permissible to leave uncovered when not praying.” (End quote from Majmu` Al-Fatawa, 22/109)
Does Small Hair Exposure Invalidate the Prayer?
If a few hairs protrude through small gaps between the threads of her Hijab, that does not invalidate her prayer, because it is very insignificant, and the majority of scholars are of the view that if a small part of the `Awrah becomes uncovered whilst praying, it is overlooked.
Ibn Qudamah (may Allah have mercy on him) said in Al-Mughni (2/287): If a small part of the `Awrah becomes uncovered , that does not invalidate the prayer. This was stated by Ahmad and by Abu Hanifah… (End quote)
Shaykh Al-Islam Ibn Taymiyah (may Allah have mercy on him) said in Majmu` Al-Fatawa (22/123): “If a small part of her hair or body becomes uncovered, she does not have to repeat the prayer according to most of the scholars. This is the view of Abu Haneefah and Ahmad.”
It says in Kashshaf Al-Qina` (1/269): The prayer is not rendered invalid if a small part of the `Awrah becomes uncovered unintentionally, even if that small part remains uncovered for a long time. (End quote)
Understanding Different Scenarios of Hair Exposure in Prayer
But if the hair that protrudes is a lot and is obvious, there are a number of scenarios:

The first scenario is when the woman does not become aware of it until after she has finished praying. In this case, it does not invalidate her prayer.
The second scenario is when the woman realizes, then covers it immediately. In this case, her prayer is not invalidated either.

It says in Al-Majmu` Sharh Al-Muhadhdhab (4/76): “If the wind moves a garment and exposes part of the `Awrah, but the person puts it back straight away, his prayer is not invalidated, because he is excused for that, so it does not interrupt his prayer.”
Shaykh Ibn `Uthaymin (may Allah have mercy on him) said: If a large amount becomes uncovered but he covers it quickly, then his prayer is not invalidated. That can be imagined if the wind blows when he is bowing and lifts his garment, but he immediately puts it back. The apparent meaning of the author’s words indicates that his prayer is rendered invalid, but the correct view is that it is not rendered invalid, because he covered it quickly, and did not uncover it deliberately, and Allah, may He be exalted, says (interpretation of the meaning): {So fear Allah as much as you are able} [At-Taghabun 64:16].” (End quote from Ash-Sharh Al-Mumti`,  2/75)

The third scenario is when the woman becomes aware of it, but she leaves it and does not cover it. In this case, her prayer is rendered invalid and she must repeat it.

Shaykh Al-Islam Ibn Taymiyah (may Allah have mercy on him) said in Majmu` Al-Fatawa (22/123): ” If a large part becomes uncovered, she must repeat the prayer straightaway, according to the majority of scholars, the four imams and others. And Allah knows best.”
What is asked about here is a small amount which does not invalidate the prayer.
And Allah knows best.