It actually is an illusion though. The narrative the brain makes up after the fact for why we did something is not perfectly correlated with the actual reason. It's just very good at its job of spinning a convincing narrative, even to itself. This is demonstrated in split brain patients: they're given instructions to do something that are shown only to one eye, the one connected to the non-speaking hemisphere, and when asked why they did it, the speaking hemisphere confidently hallucinates a wrong answer that the person seems to fully believe.