It is interesting to know that Luther did believe in purgatory, though he was not able to find any support from Scripture. He therefore argued that purgatory should not be considered as Church’s dogma, i.e. those who do not believe in it are not heretics. Below is what he wrote on purgatory (emphasis in bold is mine):
The existence of a purgatory I have never denied. I still hold that it exists, as I have written and admitted [Unterricht auf etlich Artikel. WA 2, 70] many times, though I have found no way of proving it incontrovertibly from Scripture or reason. I find in Scripture that Christ, Abraham, Jacob, Moses, Job, David, Hezekiah, and some others tasted hell in this life. This I think was purgatory, and it seems not beyond belief that some of the dead suffer in like manner. Tauler [c. 1300 to 1361, Dominican monk who, under the influence of his teacher Meister Eckhart, taught at Strassburg a deeply mystical piety] has much to say about it, and, in short, I myself have come to the conclusion that there is a purgatory, but I cannot force anybody else to come to the same result.
There is only one thing that I have criticized, namely, the way in which my opponents refer to purgatory passages in Scripture which are so inapplicable that it is shameful. For example, they apply Ps. 66[:12], “We went through fire and through water,” though the whole psalm sings of the sufferings of the saints, whom no one places in purgatory. And they quote St. Paul in I Cor. 3[:13-15] when he says of the fire of the last day that it will test the good works, and by it some will be saved because they keep the faith, though their work may suffer loss. They turn this fire also into a purgatory, according to their custom of twisting Scripture and making it mean whatever they want.
And similarly they have arbitrarily dragged in the passage in Matt. 12[:32] in which Christ says, “Whoever speaks blasphemy against the Holy Spirit will not be forgiven, either in this world or in the world to come.” Christ means here that he shall never be forgiven, as Mark 3[:29] explains, saying, “Whoever blasphemes against the Holy Spirit never has forgiveness, but is guilty of an eternal sin.” To be sure, even St. Gregory [Gregory the Great, Dialogorum Libri, IV, chap. 89. Migne 77, 396] interprets the passage in Matthew 12 to mean that some sins will be forgiven in the world to come, but St. Mark does not permit such an interpretation, and he counts for more than all the doctors.
I have discussed all this in order to show that no one is bound to believe more than what is based on Scripture, and those who do not believe in purgatory are not to be called heretics, if otherwise they accept Scripture in its entirety, as the Greek church does. The gospel compels me to believe that St. Peter and St. James are saints, but at the same time it is not necessary to believe that St. Peter is buried in Home [Rome] and St. James at Compostella [Santiago de Compostella, a famous place of pilgrimage in Spain] and that their bodies are still there, for Scripture does not report it. Again, there is no sin in holding that none of the saints whom the pope canonizes are saints, and no saint will be offended, for, as a matter of fact, there are many saints in heaven of whom we know nothing, and certainly not that they are saints, yet they are not offended, and do not consider us heretics because we do not know of them. The pope and his partisans play this game only in order to fabricate many wild articles of faith and thus make it possible to silence and suppress the true articles of the Scripture.
But their use of the passage in II Macc. 12[:43], which tells how Judas Maceabeus sent money to Jerusalem for prayers to be offered for those who fell in battle, proves nothing, for that book is not among the books of Holy Scripture, and, as St. Jerome says, it is not found in a Hebrew version, the language in which all the books of the Old Testament are written. [Jerome, Preface to the Books of Samuel and Malachi. Migne 28, 600ff] In other respects, too, this book deserves little authority, for it contradicts the first Book of Maccabees in its description of King Antiochus, and contains many other fables which destroy its credibility. But even were the book authoritative, it would still be necessary in the case of so important an article that at least one passage out of the chief books [of the Bible] should support it, in order that every word might be established through the mouth of two or three witnesses. It must give rise to suspicion that in order to substantiate this doctrine no more than one passage could be discovered in the entire Bible; moreover this passage is in the least important and most despised book. Especially since so much depends on this doctrine which is so important that, indeed, the papacy and the whole hierarchy are all but built upon it, and derive all their wealth and honor from it. Surely, the majority of the priests would starve to death if there were no purgatory. Well, they should not offer such vague and feeble grounds for our faith!
Career of the Reformer II, Luther’s Works, Vol. 32