God does this for David’s sake. The punishment is division of the nation. God had made the king’s covenant with David to unite his people under the anointed king, but Solomon broke that unity. His mission failed, so to say. That is the punishment. It is God’s grace that he may remain on the throne until he has reigned for the full forty years (as if nothing had happened!; see 1 Kings 11:41–43).
12 Yet for the sake of David your father I will not do it in your days, but I will tear it out of the hand of your son.