The Pilgrim's Progress is a fictional work by John Bunyan, it is not meant to be taken literally, it is meant to be an allegory.
For a better view of the doctrine of imputation, read the following by Bunyan:
JUSTIFICATION BY AN IMPUTED RIGHTEOUSNESS
JUSTIFICATION is to be diversly taken in the Scripture. Sometimes it is taken for the justification of persons; sometimes for the justification of actions; and sometimes for the justification of the person and action too.
It is taken for the justification of persons, and that, as to justification with God; or, as to justification with men.
As to justification with God; that is, when a man stands clear, quit, free, or, in a saved condition before him, in the approbation of his holy law.
As to justification with men; that is, when a man stands clear and quit from just ground of reprehension with them.
Justification also is to be taken with reference to actions; and that may be when they are considered, as flowing from true faith; or, because the act done fulfils some transient law.
As actions flow from faith, so they are justified, because done before God in, and made complete through, the perfections of Jesus Christ (1 Peter 2:5; Hebrews 13:15; Revelation 8:1–4).
As by the doing of the act some transient law is fulfilled; as when Jehu executed judgment upon the house of Ahab. ‘Thou hast done well,’ said God to him, ‘in executing that which is right in mine eyes, and hast done to the house of Ahab according to all that was in mine heart’ (2 Kings 10:30). As to such acts, God may or may not look at the qualification of those that do them; and it is clear that he had not respect to any good that was in Jehu in the justifying of this action; nor could he; for Jehu stuck close yet to the sins of Jeroboam, but ‘took no heed to walk in the law of the Lord God of Israel’ (2 Kings 10:29, 31).
I might hence also show you that a man may be justified even then when his action is condemned; also that a man may be in a state of condemnation when his action may be justified. But with these distinctions I will not take up time, my intention being to treat of justification as it sets a man free or quit from sin, the curse and condemnation of the law in the sight of God, in order to eternal salvation.
And that I may with the more clearness handle this point before you, I will lay down and speak to this
PROPOSITION
THAT THERE IS NO OTHER WAY FOR SINNERS TO BE JUSTIFIED FROM THE CURSE OF THE LAW IN THE SIGHT OF GOD, THAN BY THE IMPUTATION OF THAT RIGHTEOUSNESS LONG AGO PERFORMED BY, AND STILL RESIDING WITH, THE PERSON OF JESUS CHRIST.
The terms of this proposition are easy; yet if it will help, I will speak a word or two for explication. First. By a sinner, I mean one that has transgressed the law; ‘for sin is the transgression of the law’ (1 John 3:4). Second. By the curse of the law, I mean that sentence, judgment, or condemnation which the law pronounceth against the transgressor (Galatians 3:10). Third. By justifying righteousness, I mean that which stands in the doing and suffering of Christ when he was in the world (Romans 5:19). Fourth. By the residing of this righteousness in Christ’s person, I mean it still abides with him as to the action, though the benefit is bestowed upon those that are his. Fifth. By the imputation of it to us, I mean God’s making of it ours by an act of his grace, that we by it might be secured from the curse of the law. Sixth. When I say there is no other way to be justified. I cast away TO THAT END the law, and all the works of the law as done by us.
Thus I have opened the terms of the proposition.
First and Second. Now the two first-to wit, what sin and the curse is-stand clear in all men’s sight, unless they be atheists or desperately heretical. I shall, therefore, in few words, clear the other four.
Third. Therefore justifying righteousness is the doing and suffering of Christ when he was in the world. This is clear, because we are said to be ‘justified by his obedience,’ by his obedience to the law (Romans 5:19). Hence he is said again to be the end of the law for that very thing-‘Christ is the end of the law for righteousness,’ &c. (Romans 10:4). The end, what is that? Why, the requirement or demand of the law. But what are they? Why, righteousness, perfect righteousness (Galatians 3:10). Perfect righteousness, what to do? That the soul concerned might stand spotless in the sight of God (Revelation 1:5). Now this lies only in the doings and sufferings of Christ; for ‘by his obedience many are made righteous’; wherefore as to this, Christ is the end of the law, that being found in that obedience, that becomes to us sufficient for our justification. Hence we are said to be made righteous by his obedience; yea, and to be washed, purged, and justified by his blood (Hebrews 9:14; Romans 5:18, 19).
Fourth. That this righteousness still resides in and with the person of Christ, even then when we stand just before God thereby, is clear, for that we are said, when justified, to be justified ‘in him.’ ‘In the Lord shall all the seed of Israel be justified.’ And again, ‘Surely, shall one say, In the Lord have I righteousness,’ &c. (Isaiah 45:24, 25). And again, ‘But of him are ye in Christ Jesus, who of God is made unto us—righteousness’ (1 Corinthians 1:30).
Mark, the righteousness is still ‘in him,’ not ‘in us,’ even then when we are made partakers of the benefit of it; even as the wing and feathers still abide in the hen when the chickens are covered, kept, and warmed thereby.
For as my doings, though my children are fed and clothed thereby, are still my doings, not theirs; so the righteousness wherewith we stand just before God from the curse, still resides in Christ, not in us. Our sins, when laid upon Christ, were yet personally ours, not his; so his righteousness, when put upon us, is yet personally his, not ours. What is it, then? Why, ‘he was made to be sin for us, who knew no sin; that we might be made the righteousness of God in him’ (2 Corinthians 5:21).
Fifth. It is, therefore, of a justifying virtue, only by imputation, or as God reckoneth it to us; even as our sins made the Lord Jesus a sinner-nay, ‘sin,’ by God’s reckoning of them to him.
It is absolutely necessary that this be known of us; for if the understanding be muddy as to this, it is impossible that such should be sound in the faith; also in temptation, that man will be at a loss that looketh for a righteousness for justification in himself, when it is to be found nowhere but in Jesus Christ. The apostle, who was his craftsmaster as to this, was always ‘looking to Jesus,’ that he ‘might be found in him,’ knowing that nowhere else could peace or safety be had (Philippians 3:6–9). And, indeed, this is one of the greatest mysteries in the world; namely, that a righteousness that resides with a person in heaven should justify me, a sinner, on earth!
Sixth. Therefore the law and the works thereof, as to this, must by us be cast away; not only because they here are useless, but also they being retained are a hindrance. That they are useless is evident, for that salvation comes by another name (Acts 4:12). And that they are a hindrance, it is clear; for the very adhering to the law, though it be but a little, or in a little part, prevents justification by the righteousness of Christ (Romans 9:31, 32).
What shall I say? As to this, the moral law is rejected, the ceremonial law is rejected, and man’s righteousness is rejected, for that they are here both weak and unprofitable (Romans 8:2, 3; Galatians 3:21; Hebrews 10:1–12). Now if all these and their works as to our justification, are rejected, where, but in Christ, is righteousness to be found?
Thus much, therefore, for the explication of the proposition-namely, that there is no other way for sinners to be justified from the curse of the law in the sight of God, than by the imputation of that righteousness long ago performed by, and still residing with, the person of Jesus Christ."
for a history.