If you look at the account of Thomas in John 20:24-27, and compare the Greek to John 20:17, they're quite different. The Greek word translated "cling" or "touch" is ἅπτομαι
haptomai (see
https://biblehub.com/greek/680.htm).
680 háptomai (from
681 /háptō, "to modify or change by touching") – properly, "touching that
influences" (
modifies); touching
someone (
something) in a way that
alters (
changes,
modifies) them, i.e. "
impact-touching."
An example of this kind of touch might be touching firewood with a kindling stick.
Jesus apparently knew what Mary Magdalene had in her heart, something best expressed by
haptomai.
In Thomas' account, however,
haptomai is not found. These two event were very different from each other. In the account of Thomas, the word "touch" isn't even used.