The Messenger of Allah ﷺ used to pray on his mount in whichever direction it faced, but when he wanted to perform an obligatory prayer, he would dismount and face the qiblah.
كان رسول الله ﷺ يصلي على راحلته حيث توجهت، فإذا أراد الفريضة نزل فاستقبل القبلة.
Bukhari narrated it in (400) from Muslim bin Ibrahim, who said, Hisham (Dastawai) narrated to us, he said, Yahya bin Abu Kathir narrated to us, from Muhammad bin Abdul-Rahman, from Jabir, and he mentioned it.