The Gemora (Gitin 57b) states that Hashem showed Dovid Hamelech a prophecy of the destruction of the two temples and he composed Tehillim Chapter 137.