DO NOT TOUCH ME
The explanation for why Mary could not touch Christ (John 20:17) and then why they could touch Christ (Luke 24:39), indeed He invites them to touch (John 20:27) later that same Sunday, lies in understanding the types (shadow) of the Mosaic Tabernacle. It was the earthly example for the heavenly atonement.
SHADOW
The Mosaic Tabernacle was a pattern for the New.
Heb. 8:5 Who [Levitical priests] serve unto the example and shadow of heavenly things, as Moses was admonished of God when he was about to make the tabernacle: for, See, saith he, that thou make all things according to the pattern shewed to thee in the mount.
Ex. 25:9 According to all that I [LORD] shew thee [Moses], after the pattern of the tabernacle, and the pattern of all the instruments thereof, even so shall ye make it.
Annually under the Old, the High Priest atoned for sins in the Holy Place on the Day of Atonement by offering sacrifices. In regards to answering the OP, it was a day in which only the High Priest was to be present in the court; no other person was to be present.
Lev. 16:17 And there shall be no man in the tabernacle of the congregation when he goeth in to make an atonement in the holy place, until he come out, and have made an atonement for himself, and for his household, and for all the congregation of Israel.
REALITY
So, to place this Levitical shadow in context of the Melchizedekan High Priest Christ Jesus, Christ told Mary “do not touch” specifically because He had yet to ascend.
John 20:17 Jesus saith unto her, Touch me not; for [per Strong’s “assigning a reason”] I am not yet ascended to my Father:
And what was the point of Christ’s ascension that Saturday night (after the Sabbath’s sunset)?
Heb. 9: 23-24 It was therefore necessary that the patterns of things in the heavens should be purified with these; but the heavenly things themselves with better sacrifices than these. For Christ is not entered into the holy places made with hands, which are the figures of the true; but into heaven itself, now to appear in the presence of God for us:
CONCLUSION
Mary is absolutely an intriguing woman of Scripture who essentially did not care about impressions. At the earliest allowable time (about Sabbath sunset), what would become to her breathtaking delight, after the guards at the tomb, she witnessed the risen Christ first. She falls to worship, but is restricted. Did she understand the nuances of the Levitical priesthood and Atonement that had changed in Christ’s one sacrifice? Evidently she did, as Christ explained it to her. Do not touch, do not cling because I must ascend. New Testament believers also have the Book of Hebrews to explain it further; He ascends as our High Priest who died once for all to purify, to appear in the presence of God for us.
OTHER REFERENCES
https://en.wikipedia.org/wiki/Tabernacle
https://en.wikipedia.org/wiki/Scapegoat
https://en.wikipedia.org/wiki/Yom_Kippur