We find ourselves in an intimate conversation between David and God with Nathan being somewhat of an intermediary in that conversation. David realizes that he is now settled, he has a nice house, but the ark of God, the actually presence of the Lord, is just hanging out in a tent. That can't be right. Let me be sure that God is okay with me building a house for God.
I hope I was able to follow the conversation correctly that Nathan reflects to David. God puts a bit of the brakes on David building a house for God until he really understands what is expected of him. He reminds David of the past and how God led the people of Israel out of Egypt and during that time a tent was perfectly acceptable to God. God was the one who vanquished all of the foes of the people of Israel, including looking out over David and vanquishing his foes as well. During that time, a tent was perfectly acceptable.
But, and I have to check this, it seems like starting in vs.12 that God is saying that David's offspring will be the one to build His house. That makes sense because it does turn out to be Solomon who builds the temple. So here we have the promise that God's temple will be built, but it will be built not by David, but by his progeny. There is no understanding that this might be a punishment, but rather just another step in the process to ensure not only the house of the Lord, but also, and almost just as importantly at least for David, the house of David be propitiated. David accepts the words of the Lord.