The Messenger of Allah ﷺ, whenever he went out on the day of Eid, would order that a spear be set up in front of him, and he would pray facing it with the people behind him. He used to do this while traveling as well, and from that practice the rulers adopted it.
حدثنا ابن نمير قال حدثنا عبيد الله عن نافع
أن رسول الله ﷺ كان إذا خرج يوم العيد يأمر بالحربة فتوضع بين يديه فيصلي إليها والناس وراءه وكان يفعل ذلك في السفر فمن ثم اتخذها الأمراء
Its isnad is sahih. It is given at greater length in 4214, 4681, 5734, and 5840. This wording here matches the two versions of Bukhari 1:473 and Muslim 1:142, both narrated through Ibn Numayr with this same isnad.As for the statement at the end of the hadith, "and that is why the commanders adopted it," Hafiz says in Al-Fath, meaning that it was from that context that the commanders adopted the spear, going out with it before them on the day of Eid and similar occasions. This final sentence was separated out by Ali bin Mushir from the hadith of Ibn Umar, who made it part of Nafi's own words, as Ibn Majah recorded it, and I have clarified this in the book on mudraj narrations. Ibn Majah's hadith is narrated at 1:203 from Suwayd bin Saeed, from Ali bin Mushir, from Ubaydullah, and at its end it reads, "Nafi said, and that is why the commanders adopted it."