Praise be to Allah, the Lord of the World; and may His blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
The rational and sensible people agree that the enactment of punishments for crimes and finding means to deter and restrain criminals is indeed from justice and mercy. This is recognized in life, so if there are no judicial authorities, courts, prosecutions, police and the laws, the crimes and the hostile acts will spread all over the earth and human life will be disturbed. So, the presence of these things is indeed a guarantee for the sound, right and normal life.
Allah Almighty is the Wisest of the judges and the Most competent of the competent. He wants to be worshiped by His creatures and servants in their life. They obey His orders and avoid His prohibitions. They live on this earth, have children, and don't desecrate it.
He Almighty is All-Knowing and He Knows all secrets of His creatures and their apparent acts. {Should not He Who has created know? And He is the Most Kind and Courteous (to His slaves), All-Aware (of everything).} [67:14]. He knows what benefits them and what will guide them to the right path. He, Almighty, motivates us to do good deeds. He knows very well what can spoil us and our souls and what can deter us from the right path and push us into evil. Allah the Merciful knows that souls love security and benefits and hate misery and torture, so He created the Jannah (Paradise) and the Jahannam (Hell-Fire), the first for His allies and the Hell-Fire as the dwelling place for His enemies. And for that, the people should worship their Lord, desiring His reward and fearing of His torment. There is no contradiction between Allah being severe in punishment and His Forgiveness and His Mercy reaching all things He blesses His creatures and He punishes whoever deserves punishment by His justice and wisdom. {The Forgiver of sin, the Acceptor of repentance, the Severe in punishment, the Bestower (of favours). La ilaha illa Huwa (none has the right to be worshipped but He), to Him is the final return} [40:3].
Allah knows best.