John Chapter 20 Jesus is teaching about faith and belief by using Mary Magdalene and Thomas as two examples of those who have no faith to believe in what Jesus taught.
Mary Magdalene and Thomas walked in unbelief as they had no understanding of what Jesus told them in Matthew 16:21 as He foretells them of His death and resurrection. John 20:9 For as yet they knew not the scripture, that he must rise again from the dead. Neither one of them had faith to believe in what Jesus spoke to them that day.
Mary was told not to touch Him for He had not yet ascended up to His Father because she had no faith to believe what He already taught her and the rest of the disciples about His death and resurrection and going to be with His Father in heaven. She thought He came back from the dead to be with her and the disciples again like it was before His death. Same with Thomas as he also had no faith as he was not with the disciples at first in the upper room when Jesus first appeared to His disciples. After eight days the disciples, including Thomas this time, were again assembled behind locked doors for fear the Jews would also kill them for being followers of Christ as they gathered in the upper room. Thomas said he would not believe that Jesus was raised from the dead unless he could put his finger into the print of the nails, and thrust his hand into his side.
And after eight days again his disciples were within, and Thomas with them, then came Jesus, the doors being shut, and stood in the midst, and said, Peace be unto you. Then saith He to Thomas, reach hither thy finger, and behold my hands; and reach hither thy hand, and thrust it into my side: and be not faithless, but believing. And Thomas answered and said unto him, My Lord and my God. Jesus saith unto him, Thomas, because thou hast seen me, thou hast believed: blessed are they that have not seen, and yet have believed, John 20:26-29.