Whatever good, (O man!) happens to thee, is from Allah; but whatever evil happens to thee, is from thy (own) soul. And We have sent thee as a messenger to (instruct) mankind. And enough is Allah for a witness.
There is no contradiction between this statement and the preceding one that “all is from God”.
In the world-view of the Qur’an, God is the ultimate source of all happening: consequently,
all good that comes to man and all evil that befalls him flows, in the last resort, from
God’s will. However, not everything that man regards as “evil fortune” is really, in its
final effect, evil – for, “it may well be that you hate a thing the while it is good for you,
and it may well be that you love a thing the while it is bad for you: and God knows,
whereas you do not know” (2:216). Thus, many an apparent “evil” may sometimes be no more
than a trial and a God-willed means of spiritual growth through suffering, and need not
necessarily be the result of a wrong choice or a wrong deed on the part of the person thus
afflicted. It is, therefore, obvious that the “evil” or “evil fortune” of which this verse
speaks has a restricted connotation, inasmuch as it refers to evil in the moral sense of
the word: that is to say, to suffering resulting from the actions or the behaviour of the
person concerned, and this in accordance with the natural law of cause and effect which
God has decreed for all His creation, and which the Qur’an describes as “the way of God”
(sunnat Allah). For all such suffering man has only himself to blame, since “God does not
wrong anyone by as much as at atom’s weight” (4:40).
Asad, Muhammad (1980). The Message of the Quran. http://www.islamicweblibrary.com/wp-content/uploads/2020/04/55877864-54484011-Message-of-Quran-Muhammad-Asad-Islam-Translation.pdf