Foul is our version of a whole clutch of words in various Indo-European languages meaning putrid or rotten, as of corrupt flesh. In Latin the 'f' was a 'p' (just as pater became father) and putor meant 'stench'; people still say 'Pooh]' When everyone believed in the Devil, a palpable being who literally stank to high heaven, they called him the foul fiend.
Foul had already acquired its metaphorical meaning early in the Middle Ages.
But the spiritual and material worlds were closer then. Corruption in the 14th century evoked the decomposition of a corpse even when the subject was moral decay. Now, when we talk of bribery and corruption, we might say the case stinks but we don't think of charnel houses.
Foul still carries something of its original message: it is still associated, however faintly, with physical repulsion. This is despite the prosaic uses to which it had been put in the past, when it could be said of an ill-favoured person, being merely the opposite of fair. Often, from its early days, it meant not so much smelly as dirty. What we now call a dirty (uncorrected) proof used to be called a foul one. And people still tell each other it's a foul day, foul things up and shout 'foul' at football matches.
Foul survives all this, and can hit us when it wants to. When the desolate King Lear, in the storm on the heath, wails 'O] O] 'Tis foul]' we can be sure he's not talking about the weather. And don't we wail with him?