There are three passages in the New Testament which reveal a connection between forgiveness and healing.
(1) James 5:15, in the context of giving instructions about how the elders of the church are to pray for a sick person, says: "If he has sinned, he will be forgiven." The next verse emphasises the connection: "Therefore confess your sins to each other and pray for each other so that you may be healed."
(2) A similar connection is made in John 5:14 following the healing of a man at the pool of Bethesda. 'Later Jesus found him at the temple and said to him, "See, you are well again. Stop sinning or something worse may happen to you".'
If it were just from these two passages alone that we learn about the connection between sickness and sin, or forgiveness and healing, then we might conclude that sickness was the consequence of sin and that to be healed of all disease we must first repent and be forgiven. The incident recorded in John about a man born blind reveals that the disciples (and no doubt Jewish society at large) believed that disease was the result of sin: 'His disciples asked him, "Rabbi, who sinned, this man or his parents, that he was born blind?"' (John 9:2). Jesus dispels this myth with the words: '"Neither this man nor his parents sinned," said Jesus, "but this happened so that the work of God might be displayed in his life' (v. 3).
What then do we make of the first two passages I quoted? The James 5 passage teaches that unconfessed sin can be a barrier to healing, and the experience of many Christians in healing ministry (as well as healthcare professionals) has been that guilt can be a contributing factor to sickness. James counsels confession as a way of receiving forgiveness and finding healing from the burden of guilt and its physical consequences. The story in John 5 is about a man with many negative attitudes (I can go into this further at a later time perhaps), who blamed others for his condition and refused to accept any personal responsibility. After Jesus healed his physical condition He counselled him to "stop sinning", to get rid of the negative attitudes which kept him in bondage for years, or else his sinful attitudes would get him back where he was, and worse.
(3) Finally, Matthew 8 records Jesus' healing ministry - "When evening came, many who were demon-possessed were brought to him, and he drove out the spirits with a word and healed all the sick" - and then adds a quotation from Isaiah: 'This was to fulfill what was spoken through the prophet Isaiah: "He took up our infirmities and carried our diseases"'(verses 16-17). The Isaiah 53 quote is about the Suffering Servant carrying our sorrows - our transgressions and iniquities - and Peter quotes it with this meaning in 1 Peter 2:21-24. Matthew, however, says this prophecy about the Suffering Servant carrying our sins was fulfilled when Jesus healed people's diseases. I believe we are meant to conclude from this that Jesus heals the whole person - He takes away our sin and our diseases. Sometimes we find healing of physical conditions when we receive forgiveness as we are released* from our guilt and the underlying conditions which contributed to our physical suffering.
* The word "forgiveness" in Greek literally means "to let go" and can have the meaning of "release" in some contexts.