The practice of walking barefoot occasionally is considered a Sunnah (recommended practice) in Islām, primarily for several Ibrahs (Ibrah: lesson, moral).
A well-known Hadīth on this matter is when a companion, Faḍāla ibn ʿUbayd al-Anṣārī (رضي الله عنه), was asked why he wasn’t wearing shoes in Egypt. He replied, “The Prophet (Muḥammad [ﷺ, peace be upon him]) used to command us to go barefoot sometimes.”