I understand after each punishment He tells us to be good, do good so we can achieve His mercy. But isn’t faith in Him based on pure love? If I fear His punishment at all times, how could my love be unconditional for Him? I understand if I don’t want to displease God, I have to avoid the bad things that He forbade, because that is for my own good. But why would I have to be always so afraid? In a book of love and mercy, it’s hard to see such punishments, because as for me, if I love God, I would aim to refrain from those things that may hurt me.
Allah out of His love and mercy tells us what will happen if we do certain things in order to warn us - it's like as an adult I know that if I throw a rock up it will fall back down due to the law of gravity - a child may not know this - as a loving parent would I not tell my child that if you throw the rock up it will come back down and hurt you.
There is a system of cause and effect and Allah is explaining this to us. So we know if we do somethin what the effect of it will be.
It is important to fear disappointing Allah rather than fearing Him.