The concept of Purgatory comes from dissatisfaction with the idea that when people die their souls are either sent to eternal bliss in Heaven or eternal torment in Hell with no in-between. This seems counter-intuitive and unfair to a lot of people.
There is some Biblical and other evidence for the afterlife not just being the Heaven-Hell dichotomy. In Matthew 12 Jesus talks about sin that will not be forgiven in this or the next age, implying that some sin will be forgiven in the next age. In Luke 12 Jesus gives the parable of the four servants, implying different punishments for different levels of sin. In 1 Corinthians Paul talks about purification by fire, which some have taken to mean we can be redeemed after death. There is a Long-standing Christian and quasi-Christian tradition of praying for the dead, which would make no sense if the dead were already permanently assigned to Heaven or Hell.
To resolve the problem the Catholics came up with the concept of Purgatory around the tenth century. The idea was that the saints would go straight to Heaven and the unrepentant sinners would go straight to Hell, but those in between would go to Purgatory where they would suffer a Hellish fate for a while, but after a designated time had expired could then proceed to Heaven. This had the virtue of being a simple concept that average people could easily understand as well as having a measurable component – the time you needed to spend in Purgatory – which could be lessened depending on how much favour one courted with the Catholic Church.
My opinion is that the case for the afterlife not being as simple as just Heaven or Hell is well supported, but the existence of an actual physical place called Purgatory is speculative at best.