A - Thanks for the question! The easy answer is that it came from God. But, that is the easy answer. Why don't we do a little history.
Let us answer what purgatory is. I posted about this previously, so the answer to that question is already done.
In that post I also referred to the historical and biblical basis of purgatory, in fact there is ample evidence of the idea of purgatory pre-dating Christ in Jewish belief.
We can clearly see the evidence of early Christians who wrote and taught about the doctrine. Let me cite a few:
"And after the exhibition, Tryphaena again receives her. For her daughter Falconilla had died, and said to her in a dream: Mother, thou shaft have this stranger Thecla in my place, in order that she may pray concerning me, and that I may be transferred to the place of the just."-Here we see prayers for the dead. Remember that prayer does no good for those in heaven or hell.
Acts of Paul and Thecla(A.D. 160),in ANF,VIII:490
"Without delay, on that very night, this was shown to me in a vision. I saw Dinocrates going out from a gloomy place, where also there were several others, and he was parched and very thirsty, with a filthy countenance and pallid colour, and the wound on his face which he had when he died. This Dinocrates had been my brother after the flesh, seven years of age? who died miserably with disease...But I trusted that my prayer would bring help to his suffering; and I prayed for him every day until we passed over into the prison of the camp, for we were to fight in the camp-show. Then was the birth-day of Gets Caesar, and I made my prayer for my brother day and night, groaning and weeping that he might be granted to me.Then, on the day on which we remained in fetters, this was shown to me. I saw that that place which I had formerly observed to be in gloom was now bright; and Dinocrates, with a clean body well clad, was finding refreshment. And where there had been a wound, I saw a scar; and that pool which I had before seen, I saw now with its margin lowered even to the boy's navel. And one drew water from the pool incessantly, and upon its brink was a goblet filled with water; and Dinocrates drew near and began to drink from it, and the goblet did not fail. And when he was satisfied, he went away from the water to play joyously, after the manner of children, and I awoke. Then I understood that he was translated from the place of punishment."One more:
The Passion of Perpetua and Felicitias,2:3-4(A.D. 202),in ANF,III:701-702
"All souls, therefore; are shut up within Hades: do you admit this? (It is true, whether) you say yes or no: moreover, there are already experienced there punishments and consolations; and there you have a poor man and a rich...Moreover, the soul executes not all its operations with the ministration of the flesh; for the judgment of God pursues even simple cogitations and the merest volitions. 'Whosoever looketh on a woman to lust after her, hath committed adultery with her already in his heart.' Therefore, even for this cause it is most fitting that the soul, without at all waiting for the flesh, should be punished for what it has done without the partnership of the flesh. So, on the same principle, in return for the pious and kindly thoughts in which it shared not the help of the flesh, shall it without the flesh receive its consolation. In short, inasmuch as we understand 'the prison' pointed out in the Gospel to be Hades, and as we also interpret 'the uttermost farthing' to mean the very smallest offence which has to be recompensed there before the resurrection, no one will hesitate to believe that the soul undergoes in Hades some compensatory discipline, without prejudice to the full process of the resurrection, when the recompense will be administered through the flesh besides."This last reference is very telling, because we have a Church Father, Tertullian, giving commentary on Scripture and referring it to Purgatory.
Tertullian,A Treatise on the Soul,58(A.D. 210),in ANF,III:234-235
A couple of references might help:
-A conversation on purgatory
-An argument for purgatory
-Early Christians on Purgatory
If you want more info on the subject, let me know.