The Messenger of Allah ﷺ used to perform voluntary prayers on his mount during travel, facing whichever direction it took him. But when he wanted to perform an obligatory prayer, he would dismount and face the qiblah.
حدثنا عبد الرزاق عن معمر عن يحيى بن أبي كثير عن محمد بن عبد الرحمن بن ثوبان
كان رسول الله ﷺ يصلي على راحلته تطوعا حيث توجهت به في السفر فإذا أراد أن يصلي المكتوبة نزل عن راحلته واستقبل القبلة