There is no contradiction. When Jesus first resurrected, and the events of Luke 24:39 took place, He had not yet ascended to the Father in Heaven. That came later, after the Great Commission. After, or perhaps during His ascension, He ceased being a physical being and became the Life-Giving Spirit Paul wrote about in 1 Corinthians 15:45, then returned to earth on Pentecost, as such.
Eight points to consider:
1.) Jesus resurrected into the very body which He had when He died on the cross. It was a spiritual event, caused by "the glory of the Father" (Romans 6:4), but the effect was entirely physical, and occurred in the natural, material realm. Jesus plainly said, after His resurrection, that He was not mere spirit, but had flesh and bones, something spirits do not have (Luke 24:39). He invited them to touch Him and experience Him through their tactile senses, to prove the reality of His resurrected physicality. He was not a mirage, or a vision, or mass hallucination. He was present and accounted for, in true physical fashion.
2.) Christ's physically resurrected reality defies the laws of physics and all other forms of natural science and medicine. His body had massive, unhealed wounds in them, and yet, He wasn't bleeding all over the place, and felt no pain, as shown when He invited Thomas to "reach hither thy hand, and thrust it into my side" (John 20:27). No normal, human body can experience holes in the hands and feet, and have a gaping hole the size of a Roman spear-head sufficient for a man to put his entire hand into it, and be considered standard.
It appears therefore, that there was no blood in His resurrected body (an assumption, I admit, but circumstantially born out by the evidence, i.e. the bloodlessness of His resurrected, but still mortally wounded/unhealed body).
This shows that, while His body was physical and real, it had become like something the world had never seen before.
3.) Jesus could obscure Himself supernaturally, after He resurrected, so that close, personal friends and disciples, who had walked with Him, talked with Him, and had even eaten the Passover Seder with Him before He was crucified, couldn't recognize Him (Luke 24:16). This isn't something a normal human can do, without a disguise or some other act of subterfuge. Jesus somehow made His face not look like His face, or somehow blinded these men's minds from experiencing standard facial recognition.
If the former, then Jesus can shift the physical structure and appearance of His face at will, making the physical nature of His human body unlike anything that has ever existed before.
4.) Jesus can dematerialize and rematerialize Himself at will (Luke 24:31 and John 20:19 and 26). Whether He can miraculously teleport, become invisible (i.e. refract light away from Himself), or phase Himself through walls, or all of the above, the fact is, in order to do so, the nature of His physical body had, in the resurrection, to have undergone a fundamental shift in what other normal human bodies are capable of doing. In order to do what Jesus did (disappear, reappear, teleport, and/or etc.) means that Jesus had to have been able to divest Himself of any standard molecular reality, while maintaining control over His existence in order to reinvest Himself with molecular reality. Physical molecules at the microscopic level are still physical, and cannot occupy the same space as say, the molecules that made up the door Jesus must have teleported or phased through in John 20. This means His molecules passed out of physical existence into a spiritual reality we cannot comprehend, then re-emerged back into comprehensible, physical reality.
5.) Jesus can defy gravity (Acts 1:9). As Christ ascended through the atmosphere, some scientific realities must be understood. Eventually, as one ascends higher and higher in the sky, breathable oxygen disappears, and the temperature plummets dramatically. If Christ didn't somehow phase His physical body out into a spiritual reality, then it would have to be realized that Jesus can exist in a physical frame without the need to breath, or to have warmth.
Since Jesus is now immortal, it might stand to reason, of course, that He had and has no need of blood, oxygen, and etc., in order to keep Him alive, but if His body was truly physical when He resurrected (and it was) then by necessity, unless we want to think of Jesus as some merely re-animated corpse a la a horror or zombie flick, we must recognize that such a physical body must still have some kind of physical needs. Jesus could eat (Luke 24:42). He could speak, (obviously, no Scripture reference needed!), but speaking requires the ability to breath, as exhaled air passes over the vocal cords.
And yet, as He ascended physically, if no change in Him occurred, Jesus would have lost the ability to breath, and thus, to speak, in any physical, natural way, that is.
6.) If no change into a spiritual form took place some-time during the ascension, Jesus would have had to move His body to escape velocity, which is 7 miles/second, or 25,000 mph. And since escape velocity is not dependent upon the mass of the body leaving orbit, but rather upon the body from which the escaping body is departing, the same would be true of Christ's body: He would have had to move that physical form 25,000 mph to leave earth's orbit. See: here.
This is where the whole Jesus still has a physical body begins to really break down. The stress of tidal and g-forces of 25,000 mph upon an unprotected human body, which hasn't been glorified yet in heaven, would tear it apart (This is called the Roche limit. It's what causes meteors to break up in earth's atmosphere as they descend through the sky, or satellites as they lose orbit and fall into the atmosphere). We could of course argue that the power of the Most High would hold Christ's body together, but...
7.) If Christ ascended through outer space in a physical form, and God kept it from being ripped to shreds, allowed it to survive without breathing, and kept it from immediately freezing into a solid mass of ice, then at some point however long it took, Christ ascended to a realm within the physical universe, meaning the "heaven" He ascended to was merely some place in the vastness of space. If Christ's body is still physical, then the heaven He ascended to has to be physical as well, and thus, a part of the material universe. This means the heaven we all want to go to and enjoy has a geo-spatial reality and relationship to where we are today on earth, that, with enough time and the proper heading, without any collisions, we could physically travel there, taking perhaps the same route Christ took in His ascension. Newtonian physics would allow us to get there, eventually, even if it took a million earth years.
But if Christ ascended to the Third Heaven, i.e. the Heaven of Heaven's, that cannot contain God, according to Solomon, then Jesus at some point had to have transcended the Second Heaven (i.e. the Celestial Realm of the physical universe) and gone off in a spiritual unknown.
8.) With all that being said, God can re-materialize the physical body of His Son at will in the physical, material realm--meaning it still exists, just as happened when Jesus appeared to Paul on the Road to Damascus, and the glory of His appearance physically blinded Paul's eyes (Acts 9:1-9). Had it been a vision only, or some other kind of metaphysical experience, there would have been no damage to Paul's eyesight.