Haydock’s Catholic Family Bible and Commentary interprets the first passage (Jn 20:17) this way:
I will not leave you again; be not in a hurry to touch me; you shall all have this pleasure. I will remain with you some time, before my Ascension. Announce my Resurrection to my apostles. You shall see me again. This is the interpretation most modern commentators put upon this place. Others suppose that Magdalene imagined he was risen from the dead to live with men as before, like Lazarus. He addresses these words to her to disabuse her of this notion.
Thomas, on the other hand, apparently feared to go to Jesus, so Jesus was offering proof that he was alive and not a ghost or figment of Thomas’s imagination. He was saying, “Thomas, prove to yourself that I really am here by touching your hands to the wounds I sustained on the cross” (cf. Jn 20:24-29). In other words, Jesus was responding individually to different expressions of doubt.