And also of David it is written (in I Kings 1:1): "Now King David was old." And when he inclined toward death, what is written? (in I Kings 2:1): "And the days of David drew near that he should die." "King David" is not written here, but rather "And the days of David drew near." And so too Jacob: when he inclined toward death, he began to humble himself before Joseph, and said (in Genesis 47:29): "If now I have found favor in your eyes." When? When he drew near to death, as it is said: "And the days of Israel drew near that he must die."
Why King David and Jacob Lost Their Titles Before Death
Midrash Tanchuma Buber, Vayechi 3:3
ואף דוד כתיב בו והמלך דוד זקן (מ"א א א), וכיון שנטה למות מה כתיב, ויקרבו ימי דוד למות (שם ב א), המלך דוד אין כתיב כאן, אלא ויקרבו ימי דוד, ואף יעקב כיון שנטה למיתה התחיל משפיל עצמו אצל יוסף, ואמר אם נא מצאתי חן בעיניך (בראשית מז כט), אימתי כיון שקרב למיתה ויקרבו ימי ישראל למות.