It’s not only the motivation of the one punishing. The attitude of the one being disciplined opens the path to punishment.
This Scripture refers to God’s Word and His people. Discipline wasn’t working.
Zechariah 7:11, 13 (ESV)
But they refused to pay attention and turned a stubborn shoulder and stopped their ears that they might not hear … “As I called, and they would not hear, so they called, and I would not hear,” says the Lord of hosts.
Their bad attitude bought them punishment (exile), not freedom. In the end, God got their attention.