His hair is long while sparring against Sabito, but why did Tanjiro cut his hair?
Tanjiro chose to cut his hair because he was approved to enter the Final Selection. His hair grew long due to half a year of intense training, and he chose to cut it back to a preferred length once things calmed down.
He never wanted long hair, only putting up with it during his hyper-focused training.
Tanjiro’s hair grows long, decides later to cut it
In chapter #5, Sabito approaches Tanjiro. The mysterious swordsmen offers to spar despite having a wooden sword. Tanjiro, not wanting to harm the man with his real sword, points out the unfairness of the situation.
Sabito laughs hysterically and comes in close with his blade on Tanjiro. “You can’t hurt me,” Sabito says. “I’m stronger than you’ll ever be! I’ve already split a boulder!” There’s some debate over whether Sabito is stronger than Giyu, another former disciple of Urokodaki.
Tanjiro has been stuck on the “split the boulder” part of his training. Sensei Urokodaki will only allow Tanjiro to enter the Demon Slayer Final Selection if he can split the boulder, a seemingly impossible task.
Sabito criticizes Tanjiro for memorizing Total Concentration Breathing as a fact, but not implementing it within his actual body. Tanjiro admits he’s been trying hard every day, but can’t make progress. Not accepting that answer, Sabito says if Tanjiro is a true man, he’ll just “do” instead of “try.”
Tanjiro learns swordsmanship from Makomo
After Sabito easily defeats Tanjiro, the swordsman walks away. Makomo, Sabito’s sister, offers to correct Tanjiro’s bad habits and techniques. Makomo explains that Total Concentration Breathing accelerates your blood flow and heartbeat, shooting your temperature up.
After half a year of grueling training, Tanjiro approaches Sabito again. Tanjiro’s hair is long, which signifies the passage of time. Sabito approaches the fight with a real sword. Tanjiro is able to defeat Sabito in the sparring match, revealing that he actually sliced through the boulder that was giving him trouble all along.
Urokodaki, impressed with Tanjiro slicing the boulder, approves him for the Final Selection.
The following chapter, Urokodaki explains the expectations of the Final Selection while Tanjiro cuts his overgrown hair. Urokodaki also offers Tanjiro a warding mask, which is said to provide protection from evil. The mask is seemingly intended for battle against the Hand Demon, which Urokodaki captured but did not defeat.
So that’s the answer. Tanjiro chose to cut his hair prior to the Final Selection. His hair only grew long due to half a year of intense training, and he cut it once things calmed down and he had the luxury of caring about personal appearance.