It is not uncommon for literary characters to make mistakes. Sometimes, they will even commit some wrong. But the worst characters can be redeemed, or gain sudden insight, with a simple literary technique: the epiphany.
Come to Jesus
The epiphany, also known as the come-to-Jesus moment, gives your character sudden clarity. They realize something they did not before, and in this fashion find redemption or otherwise advance their plot. The epiphany is used a lot in literature. It happens a lot less frequently in reality.