This is a good question, which has been discussed by scholars. These are some views:
1. Heaven and hell exist outside of our normal time, because they are eternal. So, when we do a good act in this life, we build something at the same time in heaven (like hadith speaking of planting a tree in heaven). However, we do not experience it until after we leave this world and go through the Resurrection. Since the mi'raj occurred outside normal space and time, the Prophet (S) was able to see the eternal reality rather than being bound to our reality, which consists of normal space and time, and from which the eternal realities of Heaven and Hell are veiled. I personally favour this view.
2. When the Prophet (S) saw heaven and hell, he saw the heaven and hell of barzakh. That is, when we are in barzakh but before Resurrection, we also experience a type of heaven or hell based on our deeds, but which continues only until the Resurrection and is not eternal.
3. Allah showed the Prophet (S) a vision or appearance of what will happen in the future in Heaven or Hell. Allah can do that because Allah knows all things and can present knowledge of the unseen to anyone He wills.
Also, it should be remembered that while the idea that the Prophet (S) experienced the mi'raj is established in Qur'an and hadith, individual narrations about what he saw may be correct or incorrect.