There is no Hadith prohibiting cutting the hair to different lengths, but there is a Hadith in Sahih al-Bukhari prohibiting the Qaza’ haircut. This is when you shave parts and leave patches or a patch of hair.
ابْنَ عُمَرَ رَضِيَ اللَّهُ عَنْهُمَا يَقُولُ: «سَمِعْتُ رَسُولَ اللَّهِ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ يَنْهَى عَنِ القَزَعِ»
(Sayidina) Ibn Umar said, ‘I heard the Prophet ﷺ prohibit al-Qaza’.’ (Sahih al-Bukhari, 5920).
As seen above there is a Hadith prohibiting the Qaz’ haircut, but that does not translate to a prohibition on cutting the hair to different lengths. Unfortunately, many Muslims are being told that it is sinful to have a haircut which entails cutting the hair to different lengths. This is a very loose definition of Qaz’ and therefore mistaken. Hanafi scholars explained that the Qaz’ haircut is when parts of the head have been shaved and parts have been left with long hair.
وَأما إِذا حلق شعره كُله وَترك لَهُ ذؤابة فَهُوَ القزع الْمنْهِي عَنهُ، وَفِي: (سنَن أبي دَاوُد) من حَدِيث ابْن عمر أَنه صلى الله عَلَيْهِ وَسلم نهى عَن القزع، وَهُوَ أَن يحلق رَأس الصَّبِي وَيتْرك لَهُ ذؤابه. (عمدة القاري شرح صحيح البخاري).
As for his shaving all of his hair and leaving a braid, that is Qaz’ which has been prohibited. And in the Sunan of Abi Dawood there is a Hadith of Ibn Umar that he (the Prophet ﷺ) prohibited Qaz’. And it means to cut the entirety of a child’s hair and leave his braids. (Imam Badr al-Deen al-Ayni, Umdatu al-Qari).
See the answer below for a thorough explanation regarding the Qaz’ haircut. As for the Hadith itself, it is certainly authentic. It is narrated by Imam al-Bukhari in his Sahih with a complete chain, all such Hadith are authentic.
وأجمعت الأمة على صحة هذين الكتابين، ووجوب العمل بأحاديثهما (تهذيب الأسماء واللغات)
The Ummah is unanimously agreed that these two books (Sahih al-Bukhari and Sahih Muslim) are Sahih, and that their Hadith narrations must be acted upon. (Imam al-Nawawi, Tadheeb al-Ismaa wa al-Lughaat).
And Allah (Most High) Knows Best.
– Answered by Shaykh Noorud-deen Rashid (09.09.2021)
What is the ruling on getting a fade haircut?
Are all Hadith in Bukhari and Muslim Sahih?
See also (video):