In the accounts of Matthew and Mark both thieves on the cross mock Jesus, but Luke's account says that one of them didn't mock Him but on the contrary he rebuked the other thief and said "Lord, remember me when you come into you Kingdom." How do we understand these two contradictory accounts?
Frankly, we don't know. There are many theories as to which Gospels were used as sources for others, and plenty of disputes as to whether or not any of the Gospels were written by eyewitnesses (the author of Luke does not claim to be an eyewitness, and the author of Mark does not appear to claim to be an eyewitness for all of the events).
The other issue is that all of the Gospels record that Jesus' disciples deserted him the evening before his crucifixion, with the possible exception of John. As such, they would not be able to give eyewitness accounts of an event they were not present for. The reality is that we have no way of knowing which is more historically reliable for this account (if any). From a historical perspective, the evidence is inconclusive. What is clear historically is that Jesus was crucified beside bandits.
There were many eyewitnesses to what occurred. You didn't have to be one of the Twelve to be an eyewitness. And there were plenty of opportunities for the church in Jerusalem to learn specifics about what occurred from people who were there and then relay some part of what they knew to a gospel writer.
I use the word "specifics" and not "all the specifics".
People will remember what they remember. For instance, one eyewitness may have heard mocking from one or both of the thieves, early on; and then left or been distracted before it was all over. Or he may have stood some distance from the cross and not known anything about a quieter conversation between two of the crucifixion victims, Jesus and the man who repented.
On the other hand, a friend or relative of the repentant thief may have caught the significance of what the two said to each other; and this was stamped in his memory forever.
Even historically reliable sources are always less than precise and complete in details.
Luke's account makes it seem unlikely that both were going along with the Jewish rulers and the soldiers. It would appear that one was bold, angry and contemptuous:
One of the criminals who hung there insulted him, saying, "Are you not the Messiah? Save yourself and us."
-- Luke 23:39 (NAB)
His remarks echoed those of the people whom he overheard. His petitioning on behalf of the other "revolutionary" rings hollow in the face of the harsh rebuke from the other who seemed afraid and ashamed of his past that brought him to the Cross (v. 40)!
Was it hanging there on his cross that he came to the conclusion that the "Man in the middle" was indeed the Messiah of God? Based on his reference to "fear of God", I think not. His reaction seems to have come from independence of thought. It also appears that He understood a connection between Jesus and God:
... "Jesus, remember me when you come into your kingdom."
-- Luke 23:42 (NAB)
His words suggest, too, that he knew fear of God was important, and now he appears to have greater fear of Him than the impending death. Recognising that he had gone astray, and was now facing the agonies to come he sought forgiveness/absolution.
According to traditional interpretation, yes, both mocked, but when one of them saw and heard that He blessed and asked for forgiveness of His murderers ("forgive them, Father, they do not know what are they doing"), one of them repented and reprimanded the other, we do not know whether the other hearkened to this or not, but most probably, yes, and thus, both thieves were saved.
The three contradictory accounts can not be resolved by looking for the 'truth', because we have no way of establishing which account is true in any absolute sense. However, we can, and should, understand the contradiction from the history of the gospels themselves.
Mark's Gospel was the first account to be written, believed to be written about 70 CE. Markan priority is one of the few theories that has almost universal support from New Testament scholars. Both Matthew and Luke were subsequently based on Mark, with no evidence that either author knew anything about the crucifixion other than what they found in their common source - Mark's Gospel.
It is fairly obvious that Luke's account, in having one of the thieves repent, was written this way for theological reasons, so an initial presumption is that this account is probably not true. On the other hand, just because Mark's account was the original narrative does not mean that it was true - as with Luke, it is just as possible that Mark's author did not know. Matthew does not provide evidential support for the account this gospel shares with Mark, as its author knew nothing further about the crucifixion beyond what was found in his source, Mark's Gospel.
This means that, if indeed there were two thieves, we do not know whether one or both reviled Jesus. It is even possible that in the agony of crucifixion and the certainty of a slow and painful death, neither thief paid any heed to Jesus. John Shelby Spong says in Jesus for the NonReligious, page 112-3, Jesus was undoubtedly crucified by the Romans but, in his view, there were no thieves crucified with him, penitent or otherwise.