There's a tutorial tip that explains it. Even if nobody catches you stealing, at some point people become suspicious at all the missing items and will ask to inspect you. If you notice in the dialog the people don't outright accuse you, they only ask to check your inventory to see if you're the thief or not.