The kind of patience Allah shows to us is unmatched. He gives sustenance to those who ask and those who don't. Those who recognize him and those who don't care about him. Those who do good in his name and those who just hate hearing the word of Allah/God.
If I come and steal from you, and then you forgive me, but then I steal again and you forgive me and then again and again and again. After 32 times you would finally give up. Would you believe him the 33rd time? possibly for your child you do it more, but then still after some point you just say, I have had enough and you just move on. Allah doesn't give up that easily,
- he send messengers
- he keeps forgiving us
- he delays his wrath
- he keeps showering us with his bounties
- he keeps giving us signs to have faith in him
Prophet Noah preached for 900 years
If you ever read the gist of the story of Noah (PBUH), he preached his nation for 300 years but the nonbelievers beat him so bad, he was bleeding from his ears and passed out for 3 days, he asked God to send down his wrath, but the angels descended and said, Your lord is a merciful lord, go and guide them to the heavens again, another 300 years passed, and again Noah asked and again the Angels said your lord is a merciful lord, and this happened for a third time i.e. totally 900 years God didn't punish Noah's nation. Only after 900 years God said I shall punish this nation--when he showed enough patience and to prove that you are not of the believers even if time is given.
How merciful of a lord is our lord?!
The reason it's attributed to Allah is because our wisdom is given. It's not something we inherently own ourselves. The only thing we own as an attribute is weakness. He gave us wisdom. If we trash too much for too long then God is saying enough is enough. You don't want? Fine! I'll take it back. Hence it's attributed to him. But ultimately it's due to our own deeds. Think of it like the city taking away your driving credentials permanently, after you've ran over 10 people over the course of 30 years.
It's not exact science. But sometimes people like me disobey Allah. I repent immediately (or with some delay) or even if I don't, it's not like I take pride in doing what I did. Then there are others who openly disobey Allah left and right, take pride in doing it, enjoin others to follow, mock the religious, suppress the good, and restrict others from doing good (e.g. they force you to take off your hijab). They ignore every sign that Allah sends their way. For these people even if you give them 900 years they'll never return to Allah.