Matthew 27:44
44 The thieves also, which were crucified with him, cast the same in his teeth.
Luke 23:39-42
39 And one of the malefactors which were hanged railed on him, saying, If thou be Christ, save thyself and us.
40 But the other answering rebuked him, saying, Dost not thou fear God, seeing thou art in the same condemnation?
41 And we indeed justly; for we receive the due reward of our deeds: but this man hath done nothing amiss.
42 And he said unto Jesus, Lord, remember me when thou comest into thy kingdom.
In the Matthew account, both of the thieves mock Jesus, but in the Luke account, it seems only one does.
What we can deduce from both accounts is that both thieves originally mocked Him, but one of them repented, and one didn't.
Jesus's crucifixion took about three hours (Luke 23:44), and we know that both thieves were still alive when Jesus died (John 19:31-33). This means that they had ample time to observe the demeanor of Jesus, how He acted, what He said, and what others said to Him.
Three hours in agony is a long, long time to change your mind. Add to this the knowledge that you are facing certain death, and also having a passing knowledge of Jesus and perhaps the Scriptures are other factors that led the second thief to repent and believe in Jesus.
Even the Roman centurion that stood by Christ's side at the crucifixion, who probably knew little to nothing about the Scriptures, came to the conclusion that Jesus was the Son of God (Matthew 27:54, Mark 15:39). Another time, the soldiers sent to arrest Jesus didn't do so because of what they heard Him say (John 7:44-45). We therefore have multiple instances of an actual encounter with Jesus changing people's minds about Him completely.
Jesus was the greatest preacher to ever live, and one of His final converts on earth was a man who had mocked Him before dealing with Him and observing Him.