True, God is Love.
Yet, His love can also seem harsh to us, from a human's point of view. As He also disciplines those Whom He loves. Something which every child who gets disciplined by their parent, don't find comfortable at the time, but later on, they will look back at it with gratitude.
Discipline is meant for good, when done from love in mind. Without it which child would truly grow and learn? Which child would understand the consequences from not listening to their parents warnings and prohibitions? Not only by what they get at home, but by every trouble they may enter into when they are more left on their own.
The Discipline of God
3 For consider Him who endured such hostility from sinners against Himself, lest you become weary and discouraged in your souls. 4 You have not yet resisted to bloodshed, striving against sin. 5 And you have forgotten the exhortation which speaks to you as to sons:
“My son, do not despise the chastening of the Lord,
Nor be discouraged when you are rebuked by Him;
6 For whom the Lord loves He chastens,
And scourges every son whom He receives.”
7 If you endure chastening, God deals with you as with sons; for what son is there whom a father does not chasten? 8 But if you are without chastening, of which all have become partakers, then you are illegitimate and not sons. 9 Furthermore, we have had human fathers who corrected us, and we paid them respect. Shall we not much more readily be in subjection to the Father of spirits and live? 10 For they indeed for a few days chastened us as seemed best to them, but He for our profit, that we may be partakers of His holiness. 11 Now no chastening seems to be joyful for the present, but painful; nevertheless, afterward it yields the peaceable fruit of righteousness to those who have been trained by it.
(Hebrews 12:3-11)
Same way God sometimes keeps us away from sinful situations which would become devastating to us. Because He knows the destruction it would bring us and those near to us. Yet, we are also given a choice to not listening to His warnings, and then reaping the consequences from rebelling against Him.
"And Abraham journeyed from there to the South, and dwelt between Kadesh and Shur, and stayed in Gerar.
Now Abraham said of Sarah his wife, “She is my sister.” And Abimelech king of Gerar sent and took Sarah.
But God came to Abimelech in a dream by night, and said to him, “Indeed you are a dead man because of the woman whom you have taken, for she is a man’s wife.”
But Abimelech had not come near her; and he said, “Lord, will You slay a righteous nation also?
Did he not say to me, ‘She is my sister’? And she, even she herself said, ‘He is my brother.’ In the integrity of my heart and innocence of my hands I have done this.”
And God said to him in a dream, “Yes, I know that you did this in the integrity of your heart. For I also withheld you from sinning against Me; therefore I did not let you touch her.
Now therefore, restore the man’s wife; for he is a prophet, and he will pray for you and you shall live. But if you do not restore her, know that you shall surely die, you and all who are yours.”" (Genesis 20:1-7)