Martin Luther did not alter the Bible to fit his beliefs. Luther read the Bible in Greek. Then he struggled with a belief that he could never live a life pleasing to God.
Harboring terrible anxieties about sin and his own salvation, Luther believed that no matter how irreproachably he lived, he was unable to satisfy God.
This was a time of great "personal crisis" for Luther. His mentor advised Luther how to approach his faith in order to find peace in his faith.
Staupitz...told Luther to abandon the concept of God as judge, to focus on Christ, and simply to love God.
In this, Luther had an epiphany—a religious enlightenment. Reading and studying Paul's letter to the Romans...
...Luther realized that mankind is saved by faith and not by works.
This is critical not only to why Luther nailed his Ninety-Five Theses on the Power and Efficacy of Indulgences to the door of All Saints Church in Wittenberg in 1517, but directly answers your questions with regard to the two scriptures you have quoted.
First, recall that Luther's study of the Bible in Greek galvanized him to consider if he and the Church were doing what God wanted. And he did not begin to translate the Bible until 1521—long after he posed theological concerns that would become more than a debate as he originally intended, but would start the Protestant Reformation—based on his distress over how servants of the Roman Catholic Church were behaving.
When Luther accepted that he and all humans were not saved because of anything they did, but by faith, he understood that if someone gave large amounts of money to the Church, he would not be saved. A belief in salvation through Jesus Christ was what saved a person's soul. There were behaviors that contradicted the Bible. First, the Church taught that the worship of relics (bodies of the "venerated" dead or holy objects) would ease one's soul in purgatory. Second was the selling of indulgences: for a price, people could receive pardons for their sins. Both encouraged salvation through actions, not faith. (See Chaucer's "The Pardoner") "Pardons" were sold for profit.
They were granted on papal authority and sold by licensed agents.
A huge controversy ensued; leaders within the Church began to verbally attack each other. Luther was asked to recant. He refused. Ultimately he was excommunicated, but the Reformation would not be stopped.
Because man is judged by his faith, not his actions, consider the Scriptures you have identified:
And the dead were judged according to their works. Revelation 20:12
For by grace you have been saved...not of works. Ephesians 2:8-9
Grace is God's ability to overlook sin because of the sacrifice of Christ, who took on the world's sins when he died. The Scripture in Revelation does not say one is no longer saved based on works, but judged, for example, for showing love to others, spreading God's word, etc. Being saved, according to the Scriptures, is given for the asking, but then the saved are to "do good works." All will be judged, but one's reward in heaven is based on how one served God on the earth. Salvation is never removed from the table because someone does not, for example, give to the poor. But the Bible states that Christians are charged to be more like Jesus and to do good deeds in his name while living on earth.
Luther agreed with this. (He was also not the only person to translate the Bible from the Greek. See King James Bible.)