For sour I remember reading once it was because Acetic acid...
User ILikeJapaneseMuchOwU, in the coaxedintoasnafu subreddit,
For sour I remember reading once it was because Acetic acid and Lactic acid can kill harmful microbes, so pleasantly sour food…