Why do stores say you cannot shop barefoot?

Stores are allowed to make and enforce their own policies within reason. Although not generally required by any health codes the reason often given for requiring footwear is liability in case of injury. That may or may not be true but footwear, even flip flops, does protect your feet from being injured. Requiring footwear may also be part of an effort to maintain some level of dignity in the establishment. Barefoot shoppers with dirty feet may drive other customers away. Most stores in beach areas allow barefoot shopping.