´Mukhawwal said:` “I heard Abu Sa’d, a man from the people of Madinah, say: ‘I saw Abu Rafi’, the freed slave of the Messenger of Allah (ﷺ), when he saw Hasan bin ‘Ali performing prayer, with his hair braided. He undid it, or told him not to do that, and said: “The Messenger of Allah (ﷺ) forbade a man from performing prayer with his hair braided.”
Hadith Referenceسنن ابن ماجه / كتاب إقامة الصلاة والسنة / 1042
1؎: Because if the hair is loose during prostration (sajdah), then it too will prostrate, and when it is tied up, the hair will not touch the ground. From this it is understood that if a man has long hair, he may tie it up, but at the time of prayer (salah) he should let it loose.
´Abu Rafi narrated that :` He passed by Al-Hasan bin Ali while he was performing Salat and he had gathered his locks at the back of his head, so he (Abu Rafi) undid them, and Al-Hasan turned to him angrily. He said: "Resume your Salat and do not be angry, for indeed I heard Allah's Messenger (S) saying: 'That is the seat of Ash-Shaitan.'"
Shaykh Dr. Abdur Rahman Freywai
1: But this is for men; there is no harm for women in performing prayer with their hair tied in a braid. The Prophet sallallahu alayhi wa sallam even exempted women from undoing their braids during the ritual bath (ghusl) for major impurity. If a woman were to untie her braid during prayer, her hair might come out from under her head covering, and if a woman's hair comes out from under her head covering during prayer, the prayer becomes invalid. Moreover, untying the braid at every prayer time and tying it again after prayer would also be troublesome.
Source: Sunan al-Tirmidhi – Majlis ‘Ilmi Dar al-Da‘wah, New Delhi Edition, Page: 384