Apparently this is connected with Prayer to the Dead, which is derived from Apochrypa.
Interestingly, St. Paul prays for the late Onesiphorus saying:
May the Lord show mercy to the household of Onesiphorus, because he often refreshed me and was not ashamed of my chains. 17On the contrary, when he was in Rome, he searched hard for me until he found me. 18May the Lord grant that he will find mercy from the Lord on that day!
So prayer for the dead is not unheard of, even WITHIN the Protestant/Lutheran canon.
Also interesting is that the earliest christian burial sites have inscriptions asking BOTH for prayers for the deceased, and for the deceased to pray for those of us still living.
My understanding of Purgatory:
Scripture teaches that nothing unclean can enter heaven. We die saved, but we are still attached to sin, washed though we are. When we are in heaven that attachment will no longer be a part of us. Somewhere between death here and resurrection t here we are cleansed from this; one might say we are "purged" through the blood of Christ (NOT in addition to!). That is what purgatory is. It is primarily a STATE of purification, not a place. It's not a final destination or a work apart from Christ.
And, it's biblical. Christ refers to the sinner who "will not be forgiven, either in this age or in the age to come" (Matt. 12:32), suggesting that one can be freed after death of the consequences of one’s sins.
Similarly, Paul tells us that, when we are judged, each man’s work will be tried. And what happens if a righteous man’s work fails the test? "He will suffer loss, though he himself will be saved, but only as through fire" (1 Cor 3:15). Now this loss, this penalty, can’t refer to consignment to hell, since no one is saved there; and heaven can’t be meant, since there is no suffering ("fire") there. The Catholic doctrine of purgatory alone explains this passage.
how long should they spend time in Purgatory (in general or what's the maximum period?)
There is no set lenght of time. It could be - or feel like - close to an eternity; or be over in a minute. To my understanding this is an area open to theological speculation for the Catholic. The existence of purgatory, however, is not.
Peace of Christ.