Is there an ayah or hadith which clearly indicates that us humans were created (other reasons being as they are) out of Mercy of Allah?
Apart from the verses that mentioned the causes of creation — being a test for humans and jinn (11:7) to see who among them would worship Allah (51:56) and who would not — there is no verse in the Qur'an or an authentic hadith that I know of that stipulates or insinuates that humans were created out of Allah's mercy, and Allah knows best.
This answer relies on Shia sources.
Allah swt in the Quran states two reasons as to why He has created us:
- To get to know Him and worship Him
- To show and give His mercy
And I have not created jinns or human beings except to worship me. I do not want from them any sustenance or to feed Me. (51:57)
Imam Sadiq quotes Imam Husayn saying “To worship Me” means “to be able to know Me” and eventually “get close to Me” .
أبي عبدالله ع قال: خرج الحسين بن علي على اصحابه فقال: إن الله عز وجل ما خل العباد الا ليعرفوه، فإذا عرفوه عبدوه، فإذا عبوه استغنوا بعبادته عن عبادة من سواه
Truly God the Almighty has not created His servants except to know Him so when they know Him they will worship Him. When they worship Him they will not need to worship anyone else.
(Al-Mizan, vol. 18, p. 390)
Had your Lord wished He would have made mankind one community; but they continue to differ. Except those on whom your Lord has mercy and that is why He created them and the word of your Lord has been fulfilled: ‘I will surely fill hell with jinn and humans, all together.’ (11:118-119)
Imam Sadiq was asked by Abu Basir about the meaning of this verse and he replied:
خلقهم ليفعلوا مايستوجبوا به رحمته فيرحمهم
God created man so that they do something to deserve His mercy and then He would give them His mercy.
(Al-Tawhid by Saduq, p. 404)
In the name of God, We praise Him, seek His help and ask for His forgiveness. Whoever God guides none can misguide, and whoever He allows to fall astray, none can guide them aright. We bear witness that there is no one (no idol, no person, no grave, no prophet, no imam, no dai, nobody!) worthy of worship but God Alone, and we bear witness that Muhammad (saws) is His slave-servant and the seal of His Messengers.
”We created them not except with truth (i.e. to examine and test those who are obedient and those who are disobedient and then reward the obedient ones and punish the disobedient ones), but most of them know not” [al-Dukhaan 44:38]
God Almighty Says:
“And I (God) created not the jinn and mankind except that they should worship Me (Alone)” [al-Dhaariyaat 51:56]
It is clear that He Made us so that we can worship Him( Alone) and He wanted like this so that He can test us in deeds to see which one of us is the best in deeds.
prophet Muhammad( peace and blessings of God be upon him) said:
"The one who repents is like the one without sin."
”If you did not commit sins and turn to God seeking his forgiveness, then he would replace you with another people who would sin, ask God’s forgiveness and he would forgive them."
So it is clear from this that, it is one of the main reasons to why God created everting including us. Because, it is His decision to create us. I will provide you another example.
"Whoever brings a good deed, shall the value of ten like it. And whoever brings an evil deed will be punished with one like it. And they will not be wronged." [Al-Qur'an 3:160]
The purpose of this life is the worship of God, this life is a test. A test for us, will we worship God, or will we forget Him. This is where our focus has to begin. However, the Almighty is not in need of human worship. He did not create human beings out of a need on His part. If not a single human worshipped God, it would not diminish His Glory in any way, and if all of mankind worshipped Him, it would not increase His Glory in any way. God is Perfect. He alone exists without any needs. All created beings have needs. Consequently, it is humankind that needs to worship God. Because, God Almighty Says:
”[He] who created death and life to test you [as to] which of you is best in deed - and He is the Exalted in Might, the Forgiving.” [Quran, 67:2]
"Indeed, I am God. There is no deity except Me, so worship Me and establish prayer for My remembrance." [Quran 20:14]
But that doesn’t mean He needs our prayers, because it is something that God Almighty Said:
"Indeed, God is free from need of the worlds." [Quran 29:6]
Therefore, God does not need us to worship Him at all. He gains nothing from our worship, and our lack of it takes nothing away from God. We worship God because—through God’s wisdom and mercy—He created us that way. God made worship good and beneficial for us, from both a worldly and spiritual perspective.
Why do we worship Him? Because God Says:
"If your Lord had pleased, He would have made all people a single community, but they continue to have their differences—except those on whom your Lord has mercy—for He created them to be this way." [Quran 11:118-119]
God creating us to worship Him was inevitable. His perfect names and attributes were going to manifest themselves. An artist inevitably produces art work because he has the attribute of being artistic. By greater reason, God would inevitably create us to worship Him because He is the One worthy of worship. This inevitability is not based on need but rather a necessary manifestation of God’s names and attributes.
”Say, "He is God , [who is] One, God , the Eternal Refuge.” [Surah Ikhlaas, verses 1-2]
Conclusion: it is Because God wanted that way to happen. And He wanted that This life to be as a test for every sentient being He ever created. And it is His decision that we exist so that we can know Him.
Whatever written of Truth and benefit is only due to God’s Assistance and Guidance, and whatever of error is of me. God Alone Knows Best and He is the Only Source of Strength.