The ahadith:
إن اليهود والنصارى لا يصبغون فخالفوهم
Jews and Christians do not dye their hair so you should do the opposite of what they do.
— Bukhari
غيروا الشيب ولا تشبهوا باليهود
Change gray hair and do not imitate the Jews.
— Nasai
Can be interpreted to mean either one of the following:
- It is obligatory to dye hair
- It is recommended to dye hair
- It is permissible to dye hair
That is because depending on the context and other evidence, a grammatical command may also be used when the actual intended meaning is to convey a recommendation or a permission. For example the Quran says وإذا حللتم فاصطادوا (But when you come out of ihram then hunt) and the Prophet (ﷺ) said تسحروا (Eat Suhur). The first is a permission and the second one is a recommendation - it is virtually agreed upon that both are not obligatory despite the wording.
Some of the scholars actually have adopted the first position, that it is obligatory to dye hair, or that it is obligatory to dye hair at least once in a lifetime if the hair have turned white. This is one of the sayings attributed to Imam Ahmad ibn Hanbal.
However most have adopted the latter two interpretations, that it is recommended or permissible. They have deduced this from the behavior of the Sahaba as they better understood what the Prophet ﷺ had meant. There were two groups among the Sahaba, one dyed their hair and the other did not. Neither group condemned the other for their action. This implies that they understood it to be recommend/permissible and not obligatory. If they had considered it obligatory then it was necessary for them to reprimand those who did not dye hair under الأمر بالمعروف والنهي عن المنكر ('Enjoining Good and Forbidding Evil').
Similarly, the Prophet was often seen in a state where he had not dyed his hair, which is also evidence that it is not obligatory:
لم يختضب رسول الله صلى الله عليه وسلم إنما كان البياض في عنفقته وفي الصدغين وفي الرأس نبذ
Allah's Messenger (ﷺ) did not dye his hair; and there was some whiteness in his hair at his chin, on his temples and very little on his head.
— Muslim
رأيت رسول الله صلى الله عليه وسلم أبيض قد شاب
I saw the Messenger of Allah (ﷺ) with a white complexion and some white hair.
— Muslim
Ref:
الأمر والنهي في ذلك ليس للوجوب بالإجماع ولهذا لم ينكر بعضهم على بعض خلافه
— Sharah Nawawi
قد اختلف في الخضب وتركه فخضب أبو بكر وعمر وغيرهما كما تقدم وترك الخضاب علي وأبي بن كعب وسلمة بن الأكوع وأنس وجماعة
— Fath al-Bari