Praise be to Allah.
When a woman has given birth, the blood that comes out as a result of giving birth is called nifaas. When she is bleeding following childbirth, she should not pray or fast, and her husband should not have intercourse with her, until she becomes pure from her nifaas [i.e., the bleeding stops] or the postpartum period, which is forty days, ends, then she should do ghusl.
At-Tirmidhi (may Allah have mercy on him) said:
The scholars among the companions of the Prophet (blessings and peace of Allah be upon him), the Taabi‘een and those who came after them are unanimously agreed that the postpartum woman should refrain from praying for forty days, unless her bleeding ends before that [and she sees signs of becoming pure], then she should do ghusl and resume praying. If she sees any blood after forty days, then most of the scholars say that she should not refrain from praying after forty days. This is the view of most of the fuqaha’ and it is the view of Sufyaan ath-Thawri, Ibn al-Mubaarak, ash-Shaafa‘i, Ahmad and Ishaaq."(Sunan at-Tirmidhi 1/256).
The Permanent Committee for Ifta’ said:
If the postpartum woman sees that her bleeding has ended before the end of forty days, she should do ghusl and pray and fast, and her husband may have intercourse with her. If the bleeding continues for more than forty days, then she should regard herself as coming under the ruling on one who is pure [i.e., her nifaas has ended] because forty days is the maximum duration of nifaas according to the more sound of the two scholarly views, and the bleeding that occurs after forty days is irregular bleeding that comes under the ruling on istihaadah (irregular bleeding), unless it coincides with her normal menstrual period, in which case it is to be regarded as menses and she should refrain from praying and fasting, and it is haraam for her husband to have intercourse with her."(Fataawa al-Lajnah ad-Daa’imah 5/417).
Thus it is clear that the ghusl which is prescribed for the postpartum woman should be done after the bleeding of nifaas ends. This ghusl is obligatory.
If the tradition in some countries says that the postpartum woman should do ghusl a few days after giving birth, the purpose of this ghusl is to energise her and let her clean herself, and there is nothing wrong with that. But it does not have any impact on Islamic rulings having to do with prayer or having intercourse with her husband. The postpartum woman should not pray and her husband should not have intercourse with her until she becomes pure from nifaas [i.e., the bleeding stops], and she does ghusl.
And Allah knows best.