Do Good and Evil Come from Allah?
The question of destiny and freewill has been nagging humans all through the centuries; and each religion has attempted to answer the question in its own way.
Master or Puppet?
The noble Qur'an enunciates the view that man is not completely a master of his fate; nor is he a puppet in the hands of blind destiny. It is a fact that Allah's sovereignty is all pervading and nothing falls outside its purview; which is to say that Allah knows everything and things happen according to His Will.
The whole of creation i.e. all the things and beings in the universe are subject to the overriding power of Allah, and we humans can do nothing without Allah willing it to be so.
Allah says in the noble Qur'an what gives the meaning of:
{He created everything for its destiny (or its measure)} (Al-Furqan 25: 2)
{We created everything according to a measure or destiny.}(Al-Qamar 54:9)
In both the above verses "destiny" implies the latent capabilities of things.
But this is not to say that Allah created a universe finished and complete, bound to the iron rules of nature. On the contrary, it means only that the creation of this universe was in accordance with the grand design of the Creator.
Well-Designed and Well-Planned
There is no element of chance in the creation of this universe. Everything is well-designed and well-planned. And Allah has a foreknowledge of everything that He created. But this does not imply that human beings have been completely deprived of the freedom of action.
The foreknowledge of Allah is different from predestination. Otherwise, man will not have any freedom of will or action; and what is more, Allah Himself is then made to be inactive, as things happen according to what people call predestination. But the Glorious Qur'an clearly says that Allah is constantly active in creation. Allah Almighty says what means:
{Allah. There is no god but He, the Living, the Self-subsisting, Supporter of all. No slumber can seize Him nor sleep. His are all things in the heavens and on earth. Who is there can intercede in His presence except as He permits? He knows what (appears to His creatures as) before or after or behind them. Nor shall they compass aught of His knowledge except as He wills. His Throne does extend over the heavens and the earth, and He feels no fatigue in guarding and preserving them. For He is the Most High, the Supreme (in glory).} (Al-Baqarah 2: 255)
We may understand Allah's knowledge to be a living creative activity, which includes His fore-knowledge of events to come. The future may be conceived as an open possibility that pre-exists to be realized. This means that destiny as conceived by Islam does not negate our freedom of choice and action.
A Limited Freedom
Out of a set of inherent possibilities, we can make a free choice of those actions that are in harmony with Allah's Will; if so, we earn our reward from Allah. Thus from the point of view of Islam, humanity is free (in a limited sense) for all practical purposes, and has no excuse for making the wrong choice in the name of fate.
The Qur'anic view of humans is that they have a natural inclination to all that is good; but as we are given freedom of choice, we may choose evil against our natural tendency towards good. About divine guidance, Allah says what can be translated as:
{It is the truth from your Lord; wherefore let him who will, believe, and let him who will, disbelieve.} (Al-Kahf 18: 29)
Again we read:
{Indeed Allah does not wrong the people at all, it is they who wrong their own selves.} (Yunus 10: 44)
And:
{There is no compulsion in religion. Surely the right way has become distinct from error. } (Al-Baqarah 2: 256)
The particular Qur'anic verses you have referred to in your question should be studied against the foregoing background.
{….. If some good befalls them, they say, "This is from Allah; but if evil, they say, "This is from thee" (O Prophet). Say: "All things are from Allah." But what hath come to these people, that they fail to understand a single fact? Whatever good happens to thee is from God; and whatever evil befalls thee is from thyself…} (An-Nisaa' 4:78-79)
Good and Bad: From Allah's Will
First, it is mentioned that all things are from Allah; and then it is stated that good happenings come from Allah and evil happenings come from humans.
If we look for the correct interpretation of the verses above, we can see that there is no contradiction there. In fact, Allah Almighty is the ultimate source of all that is happening.
Consequently, all good that comes to man and all evil that befalls him flow originally from Allah's will: that is, everything is from Allah. And when man uses his freewill and makes a wrong choice out of several available options, evil follows. And we should remember that evil is the absence of good; or its opposite that follows a wrong choice by man. Thus it is true that evil happenings come from man.
It is also possible that what appears to be evil may very well turn out to be good in the end. In such cases evil is no more than a means of spiritual growth for man, and need not necessarily be "evil" in reality. And remember that:
{Allah does not wrong anyone by as much as an atom's weight.} (An-Nisaa' 4:40)
We can also view the whole matter from a different angle as well. Everything is from Allah; and so we are from Allah. Evil is from us ourselves; but since we are from Allah, the evil that comes from us can also be attributed to the original source of all, namely Allah Almighty. So there is absolutely no contradiction in the verses you referred to.
The Qur'anic concept of destiny includes the ideas of measurement, proportion, guidance and the completion of the creative process. We may say that it is the Law of Allah operating in the whole of His creation, including man.
In the case of humanity, the Divine Law includes the idea of freewill too. Allah has created everything with a purpose, a purpose that is attained by the completion of the process of creation.
In this scheme, humanity alone has a unique status as people can exercise freewill, where "evil" has a significant role along with good.