The Holy Quran states that every matter occurs by the will of Allah Almighty, while the Hadith says:
وَالشَّرُّ لیس إِلَیك
Reference: (Sahih Muslim)
Translation: "O Allah! There is no evil in You," thus this Hadith contradicts the Holy Quran. Therefore, it is unreliable.
First Point
This Hadith is not contrary to the Holy Quran; the Quran also contains statements regarding evil.
وَّاَنَّا لَا نَدْرِيْٓ اَشَرٌّ اُرِيْدَ بِمَنْ فِي الْاَرْضِ اَمْ اَرَادَ بِهِمْ رَبُّهُمْ رَشَدًا
Reference: (Al-Jinn:10)
Translation: And we do not know whether evil is intended for the people on earth or their Lord intends for them good.
وَخَلَقَ كُلَّ شَيْءٍ ۚ وَهُوَ بِكُلِّ شَيْءٍ عَلِيْمٌ
Reference: (Surah Al-An'am:101)
Translation: And He created everything and He is, of all things, Knowing.
From these verses, it is understood that the Creator of everything is Allah Almighty, in which all things, good and evil, are included.
Second Point
Scholars have given various explanations regarding the meanings of this Hadith; studying them makes it clear that this Hadith is not contrary to the Holy Quran.
Imam Nawawi, may Allah have mercy on him, while explaining and interpreting [والشر لیس إلیك], states:
"All matters occur only by the will and command of Allah, and everything, whether good or evil, is His creation. Therefore, regarding the interpretation of these words of the Hadith, scholars have five opinions, which are as follows."
➊ One cannot attain nearness to Allah through evil. This opinion is attributed to Nazar bin Shamil, Khalil bin Ahmad, Yahya bin Ma'in, Ishaq bin Rahwayh, Al-Azhari, and Abu Bakr Ibn Khuzaymah, may Allah have mercy on them.
➋ Imam Muzani and others have interpreted that individually, evil cannot be attributed to Allah. That is, one should not say, "O Creator of monkeys and pigs! O Creator of evil!" although Allah is the Creator and Lord of everything. In other words, evil can be included in general terms, but specifically mentioning evil and attributing it to Allah is not permissible.
➌ It is also explained that evil does not ascend to Allah; rather, only pure words ascend to Allah.
➍ Evil is not attributed to Allah Almighty. This is because Allah Almighty has created evil under some wisdom; evil is attributed to the creation.
➎ Imam Khatabi says: "والشر لیس إلیک” is exactly like when a person is counted among his people and it is said: "فلان إلی بني فلان” meaning such and such a person is from such and such a nation.
Reference: (Sharh Sahih Muslim by An-Nawawi: 3/1361, 1362)
Explanation of Imam Tahawi, may Allah have mercy on him
Imam Tahawi states:
"[والشرلیس الیک] meaning O Allah! You have not created evil alone, rather whatever You have created is not devoid of wisdom. According to this wisdom, it is also good, but it may be evil for some people. This is a partial type of evil which is relative to the servant, while Allah Almighty is absolutely free from evil or evil in general. This is the meaning of [There is no evil with You]."
Reference: (Sharh al-Aqidah al-Tahawiyyah by Ibn Abi al-Izz al-Hanafi, p. 362)
Explanation of Allama Hafiz bin Ahmad Hakami, may Allah have mercy on him
In response to a question, Allama Hafiz bin Ahmad Hakami says:
"Despite the fact that the Creator of everything is Allah Almighty. The meaning is that all actions of Allah are solely and entirely composed of good, both in the sense that they are attributes of Allah's essence and that they emanate from Allah. There is no aspect of evil in them in any way. Every decision of Allah Almighty is based on justice, every action is based on wisdom and justice. Allah Almighty deals with everything in a manner befitting it. And if there is evil in anything, it is in relation to the servant. It is the result of his actions. As Allah Almighty says:
وَمَآ اَصَابَكُمْ مِّنْ مُّصِيْبَةٍ فَبِمَا كَسَبَتْ اَيْدِيْكُمْ وَيَعْفُوْا عَنْ كَثِيْرٍ
Reference: (Ash-Shura:30)
Translation: And whatever misfortune befalls you, it is because of what your own hands have earned; and He pardons much.
Also, the Divine command is:
اِنَّ اللّٰهَ لَا يَظْلِمُ النَّاسَ شَيْـــًٔـا وَّلٰكِنَّ النَّاسَ اَنْفُسَھُمْ يَظْلِمُوْنَ
Reference: (Yunus:44)
Translation: Allah does not wrong the people at all, but the people wrong themselves.
Reference: (200 Questions on Islamic Creed, by Hafiz bin Ahmad Hakami, p. 45)
Explanation by Sheikh Muhammad Salih Al-Uthaymeen, may Allah have mercy on him
Sheikh Muhammad Salih Al-Uthaymeen, may Allah have mercy on him, says:
There can never be any evil in the actions of Allah because evil, in terms of condition and outcome, cannot be good, and it is not possible for Allah's actions to be devoid of good. However, it can be so from one aspect, because what Allah has decreed as evil will ultimately have a good end. What is evil for one people will be a cause of good for others. Have you not seen that when Allah sends down heavy rain, which destroys the crops of some people, on the other hand, it benefits the land and other people? So, for those who benefit, this rain proves to be good, and for those who suffer loss, the aspect of evil is seen in it. From one aspect, there is evil in it, and from another aspect, there is good.
Similarly, what Allah has decreed as evil for humans is actually good in reality.
Reference: (Sharh Riyadh As-Salihin by Sheikh Ibn Uthaymeen, 1/68)
Summary
From the statements and explanations of the scholars, it becomes clear that this blessed hadith does not contradict the Holy Quran.