Walking without shoes in public is not illegal.
However in public buildings it's a policy that you have to wear shoes when in the public building for your own safety and their safety as well as the people in the building.
The place can ask you to leave but it's not illegal to not wear shoes.
Going barefoot outside is generally safe but if you're in places such as a public park then it may not be a good idea to go barefoot outside.
In parks and other places that you don't know what has been there such as dogs pooping, animals pooping etc then you could get bacteria on your feet which could make you sick.
I used to go barefoot in parks though as a kid and I survived but it still could have caused health issues.
In my own backyard or front yard I do go barefoot outside when it's nice out as I hate wearing shoes and when I don't need to wear shoes I don't wear shoes.
But in public places I always wear shoes.
I've seen some people walking around in public without shoes but they have a pair of sandals with them to put on if they go into a store.
If you go into a store or public place you have to wear shoes as part of their policy.