Allah is the Creator of everything in the truest sense of the word.
We tend to assume that Allah only created the material things that we see, like the stars and the other celestial bodies, and everything between them, and also what lies within them.
However, Allah has also created other notions that we consider abstract, like time, and a sense of awareness of it within us. He has also created (written) qadr, or destiny, for each of His creation, and He can bend time as He pleases to make His Messenger (SAWS) see things that will happen in the "future," a notion that makes sense to us as humans.
Other than this, Allah can even bend space, so that we tend to see our earth and other bodies and the relation between them, insofar as their orbits are concerned. However, the reality of space may be vastly different from how we perceive it.
Ultimately, the entire universe that we see lies within our heads, since it is only our perception of it.