Hebrews 12:6 For the Lord disciplines the one He loves.
God is gracious and merciful, but He is also holy and just. This requires Him to confront sin, which destroys the people He loves. Unless He can turn the hearts of His people from their wicked ways, they will not only harm themselves but also miss out on an intimate relationship with Him.
If you are being disciplined for sin, remember that it is because God loves you and wants to turn your heart back toward Him. Be grateful that God cares enough about you to want the very best for you, even if it means temporary pain, but it can bring permanent blessing.