David HaMelech said of this practice (Tehillim 30:12):
הפכת מספידי למחול לי פתחת שקי ותאזרני שמחה
You turned my mourning into dancing for me, you removed my socks and girded me with happiness.
So we see that it’s not simply not wearing shoes, but actively wearing socks that indicates mourning. (Perhaps the common custom nowadays to wear socks under our shoes is meant to be a sign of mourning the Beis HaMikdash.)
What is the reason for this? David HaMelech says further in Tehillim 147:9:
נוֹתֵ֣ן לִבְהֵמָ֣ה לַחְמָ֑הּ לִבְנֵ֥י עֹ֝רֵ֗ב אֲשֶׁ֣ר יִקְרָֽאוּ׃
Who gives to an animal its bread, to young ravens when they call out?
Who, indeed, is it who gives food to young ravens? It must be the Angel of Death, who smites creatures, which the ravens then eat.
“Bread,” of course, is a euphemism for living creatures; as we find in Bereishis 39:6:
הַלֶּ֖חֶם אֲשֶׁר־ה֣וּא אוֹכֵ֑ל
The bread which he eats
which, as Rashi explains,
This is [Potiphar’s] wife
Rashi further notes on Bereishis 37:33:
חיה רעה אכלתהו. [...] סוֹפוֹ שֶׁתִּתְגָּרֶה בוֹ אֵשֶׁת פּוֹטִיפַר.
”A wild animal ate him” - [...] His end is that the wife of Potiphar will drag him.
So we see that Potifar’s wife is a wild animal, and she is called “bread,” so we may deduce that living creatures in general are called “bread.”
Okay, back to the passuk in Tehillim 147. Having established that we’re talking about the Angel of Death, the passuk continues (v. 10):
לֹ֤א בִגְבוּרַ֣ת הַסּ֣וּס יֶחְפָּ֑ץ לֹֽא־בְשׁוֹקֵ֖י הָאִ֣ישׁ יִרְצֶֽה׃
Not in the strength of a horse does he desire, nor in the shins of man is he appeased.
The Angel of Death doesn’t desire strength, so the practice is to mourn and refrain from many activities. He is not appeased by the shins of man, so the practice is to cover them with socks.