The connection is taken from the LXX:
LXX 2 Reigns 7:8-14 NETS
8 And now this is what you shall say to my slave David: This is what the Lord Almighty says: I took you from the sheepfold for you to be leader for my people, for Israel 9 and was with you in all to which you went and destroyed all your enemies from before you and made you renowned like the name of the great ones who are upon the earth. 10 And I will appoint a place for my people Israel and will plant them, and they will encamp by themselves, and they will be distressed no more, and a son of injustice shall not add to afflict them as formerly 11 from the days that I appointed judges over my people Israel, and I will give you rest from all your enemies, and the Lord will tell you that you will make a house for him. 12 And it will be if your days are fulfilled and you lie down with your fathers, that I will raise up your offspring after you who shall be from your belly, and I will prepare his kingdom; 13 he shall build me a house for my name, and I will restore his throne forever. 14 I will be a father to him, and he shall be a son to me, and if injustice comes, then I will punish him with a rod of men and with attacks of sons of men.
The Greek translates יהוה צבאות who speaks to Nathan (verse 7:8) as κύριος παντοκράτωρ, Lord Almighty. Thus in the Greek translation, the entire message Nathan is to deliver to David is from κύριος παντοκράτωρ.
Paul cites only the first portion of verse 7:14. He adds daughters which is absent in the Hebrew and Greek text. This prevents an overly literal understanding to mean God is father only to men. Paul has interpreted the promise of God's Fatherhood as one made to both male and female.
Finally, Paul truncates verse 7:14 after the promise of fatherhood, but he adds who it was that made the promise, λέγει κύριος παντοκράτωρ, says Lord Almighty, quoting the LXX verbatim.
As he often does, Paul connects multiple Scriptures to convey a single point:
2 Corinthians 6:14-18 ESV
14 Do not be unequally yoked with unbelievers. For what partnership has righteousness with lawlessness? Or what fellowship has light with darkness? 15 What accord has Christ with Belial? Or what portion does a believer share with an unbeliever? 16 What agreement has the temple of God with idols? For we are the temple of the living God; as God said, “I will make my dwelling among them and walk among them, and I will be their God, and they shall be my people. 17 Therefore go out from their midst, and be separate from them, says the Lord, and touch no unclean thing; then I will welcome you, 18 and I will be a father to you, and you shall be sons and daughters to me, says the Lord Almighty.”
The singular idea is believers, we (verse 16) are the Temple of the Living God, or the living Temple of God.1 This is possible because Christ has no accord or harmony with Belial, a name for Satan. The Scriptures Paul uses to show this separation and God's intent to dwell with His people begins verse 16. The NKJV points to Leviticus 26:12 (also Jeremiah 32:38 and Ezekiel 37:27) as what Paul is citing. In verse 17 he uses Isaiah 52:11 (also Ezekiel 20:34, 41). In verse 18 he uses 2 Samuel 7:14 and 7:8. By ending with λέγει κύριος παντοκράτωρ, says Lord Almighty, Paul in effect attributes all to Lord Almighty.
Obviously Paul has taken from several places the idea of God dwelling with His people. The key is how he applies God's response to David's desire to build a singular and stationary Temple in Jerusalem. Paul works from the promise to be a Father. Thus believers will be His sons and daughters. Wherever His children are (in this case Corinth) He dwells in their midst. Since they are in His presence, they should avoid that which is unclean, go from the midst (of that which is unclean), and be welcomed by Christ (who has no harmony with Belial).
All of this Paul states was λέγει κύριος παντοκράτωρ, spoken by Lord Almighty.
1. Literally, we for temple of/from God are living.