All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
The story that you mentioned in the question is not sound as Marfoo' (attributed) to the Prophet as in "As-Silsilah Adh-Dha’eefah" by Al-Albaani because after mentioning the story, he said: “It is Baatil (false) as a Marfoo' Hadeeth.”
Then, he mentioned that it is sound as a Mawqoof (attributed to a Companion) as it was reported from Ibn ‘Umar who reported it from Ka’b Al-Ahbaar; so it is one of the Israa'eeliyyaat (narrations of Jews and Christians) that are not taken into account or considered as evidence.
Allaah Knows best.