purgatory is an intermediate state after physical death in which some of those ultimately destined for heaven must first, so as to achieve the holiness necessary to enter the joy of heaven.
the reason of indulgences is that it was to purchase an exemption from punishment for some types of sins.