Rabbi Eliezer said: In the hour of the death of Jacob he called to his son Joseph, and said to him: O my son! Swear to me by the covenant of circumcision that thou wilt take me up to the burial-place of my fathers in the land of Canaan to the Cave of Machpelah. The ancients used to swear by the covenant of circumcision prior to the giving of the Torah, as it is said, "Put, I pray thee, thy hand under my thigh" (Gen. 47:29), and "he sware unto him" (Gen. 47:31).
He kept (the oath) and did (accordingly), as it is said, "And he said, Swear unto me" (ibid.). And all the mighty men of the kingdom went up with him to bury him, and to show loving-kindness to Jacob his father, as it is said, "And Joseph went up to bury his father" (Gen. 50:7). The camp of Israel numbered 5040 (people). All the (people of the) land were bringing food on account of the famine to the camp of Joseph.
The Holy One, blessed be He, said to them: Ye have shown loving-kindness to Jacob, My servant, I also will give you your reward, and also unto your children in this world. When the Egyptians died in the Reed Sea they did not die in the water, but they were deemed worthy to be buried in the earth. The Holy One, blessed be He, said to them: Ye have submitted yourselves to the divine punishment; I also will give you a place of burial, as it is said, "Thou stretchedst forth thy right hand, the earth swallowed them" (Ex. 15:12).