The LORD God of Israel had appeared to Solomon twice and warned him not to worship foreign gods. But Solomon disobeyed and did it anyway. This made the LORD very angry,
One night while Solomon was in Gibeon, the LORD God appeared to him in a dream and said, “Solomon, ask for anything you want, and I will give it to you.”
Some time later, the LORD appeared to Solomon in a dream and said: I heard your prayer, and I have chosen this temple as the place where sacrifices will be offered to me.