Towards the end of Birkat Ha’mazon, we recite the verse, "Magdil Yeshu’ot Malko" (Tehillim 18:51). On Shabbat and Yom Tob, however, we recite instead the verse, "Migdol Yeshu’ot Malko" (Shemuel II 22:51). Some Rabbis explained that this change is made because David wrote the verse, "Magdil Yeshu’ot" before he became king, and the verse, "Migdol Yeshu’ot" after he became king. As such, the phrase "Migdol Yeshu’ot" is associated with royalty, and it is therefore appropriate to recite this verse on Shabbat and Yom Tob, which are "kings" in relation to ordinary weekdays.
"Migdol" is recited on Hol Ha’mo’ed and Rosh Hodesh, as well.
The Ben Ish Hai (Rav Yosef Haim of Baghdad, 1833-1909) writes that "Migdol" should be recited even at the Melaveh Malka meal eaten on Mosa’eh Shabbat, particularly if the meal is eaten within four hours of the end of Shabbat. Even though the meal is eaten after Shabbat, it is nevertheless associated with Shabbat, and so it is appropriate to recite "Migdol" in Birkat Ha’Mazon after this meal.
The Ben Ish Hai also rules that "Migdol" is recited on Purim, because there is a special "He’ara" (spiritual "illumination") on this day. It is also recited in Birkat Ha’mazon at the feast celebrating a Berit Mila. The Poskim say that "Migdol" should be recited at a Siyum (celebration of the completion of a tractate of the Talmud), as well.
Summary: The verse, "Magdil Yeshu’ot Malko" in Birkat Ha’mazon is replaced with "Migdol Yeshu’ot Malko" on Shabbat, Yom Tob, Purim, Rosh Hodesh and Hol Ha’mo’ed, and at a Melaveh Malka, Berit Mila, or Siyum.