If a higher octane cured the problem then it was an issue with the gasoline.
As for why the problem randomly started, it could have been bad fuel that was diluted with good fuel up until a certain point.
What I mean is, perhaps higher octane fuel is denser/heavier and resides at the bottom of the tank near the pump. Once that higher octane fuel was used up all that was left was the lower octane fuel which caused the knocking.
Of course, this is just speculation and I could very well be talking out of my ass

.