Thank you for your question. The issue of punishment can be understood in a number of ways. According to one understanding, which is perhaps the most prevalent, God would punish a person for not believing as that is the consequence of their bad use of free will. He has endowed humans with the ability to know Him, and has given them the bounties of this life, but with a responsibility to choose the correct way. As such misusing those bounties and choosing the wrong way results in punishment.
Another way to visualize punishment is to understand that God doesn't punish humans for their actions, but rather the real manifestation of the actions of a human in the next world is in line with the reality of that action. Bad actions manifest as punishment and good actions manifest as reward. With this view, God warns us of our own punishment of ourselves through the witnessing of the reality of our bad actions in the next world and that is truly what we have earnt.
May you always be successful