Why did Hashem tell Nasan that night?
Rashi citing R. Chanina bar Papa, in Midrash Shmuel 26:1: The man I send to you (David) is quick. Perhaps he will hire workers [to build the Beis ha'Mikdash], and [when I tell him that he may not, he must pay them, and] I will cause him to lose! Tell him quickly.
Rashi citing R. Simon, in Midrash Shmuel 26:1: The man I send to you is wont to vow - "Asher Nishba la'Shem Nadar la'Avir Yakov; Im Avo El Ohel Beisi
Malbim: Indeed, the verses show that David did vow! Radak (132:3,4) - he will not enjoy dwelling in his house or resting on his bed, until he will find the place for the Mikdash.
Sanhedrin 104b: A verse praises Shlomo for building the Mikdash quickly, and he took seven years to do so! (Could David not eat until he builds it?! Perhaps he would vow until he begins building it, or not to eat more than needed to stay alive until he finished building it. Some explain "Im Eten Shenas l'Einai" (Tehilim 132:4) like this. - PF)