The prophecy in question was actually made by Joseph of Egypt, and was first recorded in the Book of Mormon, in the third chapter of Second Nephi. Joseph of Egypt prophesied of the choice seers to come, namely Moses, and Joseph Smith:
14 And thus prophesied Joseph, saying: Behold, that seer will the Lord bless; and they that seek to destroy him shall be confounded; for this promise, which I have obtained of the Lord, of the fruit of my loins, shall be fulfilled. Behold, I am sure of the fulfilling of this promise;
15 And his name shall be called after me; and it shall be after the name of his father. And he shall be like unto me; for the thing, which the Lord shall bring forth by his hand, by the power of the Lord shall bring my people unto salvation. (2 Nephi 3)
The Lord inspired the Prophet Joseph Smith to restore truths to the King James Bible text that had become lost or changed since the original words were written. These restored truths clarified doctrine and improved scriptural understanding.1
The record of this prophesy from ancient Joseph's time was preserved in the Brass Plates, and subsequently in the Gold Plates, then translated by Joseph Smith. Keep in mind that Mormons believe Joseph literally translated an ancient record. The question has been put forward by more than one speaker, as to what Joseph Smith must have felt or thought after realizing he was translating a prophecy about himself, and discovering that other prophecies in the Bible were in reference to him (see Prophecies in the Bible about Joseph Smith).
It is apparent that the prophecy in question took place during the events recorded in Genesis 50, hence why Joseph restored them to that section of scripture while completing the work of retranslating the Bible.