The Prophet ﷺ prayed in his sandals when clean, and said: “Differ from the Jews, for they do not pray in their shoes or leather socks.” (Abū Dāwūd — ṣaḥīḥ). Check for impurity first — and never soil a carpeted masjid.
العربية: عن شدّاد بن أوس رضي الله عنه أنّ رسول الله ﷺ قال: «خالِفوا اليهود، فإنّهم لا يُصلّون في نعالهم ولا خِفافهم». (أبو داود). وكان ﷺ يُصلّي في نعليه إذا كانتا طاهرتين. (البخاري).
When praying outdoors on clean ground, you may pray in clean shoes — keep carpeted masjids clean.