How does Allah know what I will do before I even do it?
We ask this question because we think time applies to God, when it only applies to us on this low material plane. In reality, God knows all outside of any limitation.
For Allah, the Mahdi returned when Adam was created.