It is not contradictory that Allah is more merciful than a mother to her child while He punishes the disbelievers and the disobedient Muslims
Some people ask: How can we reconcile the Prophet's (peace be upon him) saying: (Allah is more merciful to this mother than to her child) with the fact that He punishes the disbelievers and the disobedient Muslims in the Hereafter? The answer: First: We must distinguish between Allah's general mercy in this world and His special mercy in the Hereafter. He is exalted, He shows mercy to all His servants in this world, believers and disbelievers, obedient and disobedient, a general mercy, providing them with sustenance, food, drink, and healing. For without Allah's mercy, no one would breathe air, nor would anyone find a drop of water. And His mercy to them is that He sent them messengers, guided them to the path of eternal happiness, and gave them respite while they disobey Him. And other forms of mercy that are countless. And by this, He is more merciful to all His servants than a mother to her child, for He who made the mother merciful must be more merciful than her. As for His special mercy in the Hereafter, it is only for the believers, and the disbelievers have no share in it. Thus, the disbeliever moves from Allah's mercy to His justice, for he has excluded himself from qualifying for this special mercy in the Hereafter. Allah says: (My punishment will strike whom I will, and My mercy encompasses all things; I will prescribe it for those who fear Me and give zakah and those who believe in Our verses) Al-A'raf 156. Note: (And My mercy encompasses all things)...this is the general mercy in this world. (So I will prescribe it): meaning I will grant it to those who have these qualities: (those who fear Me and give zakah and those who believe in Our verses). As for the disobedient Muslims, if Allah wills to enter them into Hellfire with justice, they will not abide in the Hellfire forever, for He does not equate them with the disbelievers. Secondly: Just as Allah is characterized by mercy, He is also characterized by justice. Allah's names and attributes do not contradict each other. If someone says: We expect Allah to show mercy to the disbeliever in the Hereafter because He is the Most Merciful, and mercy is His attribute, we say: This would mean He would not be just, and justice is His attribute. Allah says: (Or do those who commit evil deeds think that We will make them like those who believe and do righteous deeds, equal in life and death? Bad is their judgment) and He says: (Or shall We treat those who believe and do righteous deeds like the corrupters of the earth? Or shall We treat the righteous like the wicked?) For the perfection of Allah's wisdom and justice is to distinguish between His friend and His enemy, those who obey Him and those who disobey Him, His servant, and those who serve others. Otherwise, equating all of them would be injustice that contradicts justice and wisdom. And Allah knows best. The answer is taken from the Islam Question and Answer website with summarization and rephrasing.