[Machine] The Messenger of Allah ﷺ forbade the use of harmful medicine, and these two Hadiths are understood to prohibit the use of intoxicants for medical treatment or the use of any prohibited substance except in cases of necessity, in order to reconcile between them and the Hadiths of the Quran and Allah knows best.
نَهَى رَسُولُ اللهِ ﷺ عَنِ الدَّوَاءِ الْخَبِيثِ وَهَذَانِ الْحَدِيثَانِ إِنْ صَحَّا فَمَحْمُولَانِ عَلَى النَّهْيِ عَنِ التَّدَاوِي بِالْمُسْكِرِ أَوْ عَلَى التَّدَاوِي بِكُلِّ حَرَامٍ فِي غَيْرِ حَالِ الضَّرُورَةِ لِيَكُونَ جَمْعًا بَيْنَهُمَا وَبَيْنَ حَدِيثِ الْعُرَنِيِّينَ وَاللهُ أَعْلَمُ