Why did David compose this Mizmor?
Rashi: It was in his old age, after all his afflictions passed and he was saved from all of them. 1 Malbim - he thanks Hashem for this, and discusses two ways that Hashem conducted with him. (a) At a time of serenity, he thanks Hashem that no evil came to him. (b) At a time of great afflictions, he tells of Hashgachah via nature - when he did not merit, just due to his Tefilah, Hashem saved him via nature. And when he merited, Hashem saved him via miracles, without Tefilah.
Malbim (Shmuel II, 22:1, citing Mahari): He composed it in his youth, when he was amidst his afflictions. Each time Hashem saved him, he sang it - "b'Yom Hitzil Hashem Oso." In David's old age, he gathered all his praises into a special Sefer (Tehilim), for one who isolates himself to say in front of Hashem for all particular things that one needs in his lifetime, he will find a Mizmor or Tefilah to pray. It has wondrous Segulos; it was written with Ru'ach ha'Kodesh. This Mizmor was repeated there, for one who was surrounded by many difficulties and was saved from them like David, to pray it. Since "Tefilah l'Ani Chi Ya'atof" (Tehilim 102) is for one who isolates himself, he changed many things to apply to an individual's needs.
How did David know that all his afflictions had passed? Adoniyahu's rebellion was close to David's death! Perhaps he sang this afterwards. (PF)
Who is called "Eved Hashem"?
Radak: It is one who puts all his strength and intent in Hashem, in all his matters.
Why does David call himself "Eved Hashem" specifically in this Mizmor?
Radak: Hashem saved him from every danger, like a master who saves his slave.
Why was Sha'ul singled out? He was among David's enemies!
Rashi (from Sifri Ekev 52): He was the biggest enemy and pursuer of David. This is like "Re'u Es ha'Aretz v'Es Yericho" (Yehoshua 2:1).
Radak: Sha'ul was equal to all of David's enemies.
Malbim: He was in the greatest danger from Sha'ul.
This Shirah is also in Tehilim (Perek 18), with differences. Why is it also here?
Malbim: Refer to 21:1:1:2.