CASE #1: "Joe" was immersed into a denominational church, believing that he was saved before he ever entered the baptistery. Clearly, in such a case he was not baptized for the remission of his sins (cf. Acts 2:38) since he thought they were already forgiven previously. Thus, his understanding of baptism was fundamentally flawed. If he later learns the truth pertaining to baptism and its purpose, Joe would be wise to be immersed again (but this time for the right reason). If one has doubt (about anything), it is always better to pursue the course of action that removes the doubt, where possible.
CASE #2: "Jim" was immersed for the remission of sins as an early teenager. He understood little more than the basics. However, in his young adult years he learned a great deal more about the Bible and God's scheme of redemption. After acquiring significantly greater knowledge, Jim wonders if he should now be baptized again, since he didn't understand many of the things years ago that he does now. In Jim's case, being rebaptized is not necessary. Surely the 3000 on Pentecost (cf. Acts 2:41ff) who responded favorably to the gospel message learned a lot more after that day, yet there was no need to submit to immersion a second time. They had been added to the church (cf. Acts 2:47) and were saved. Their baptism was valid. When such a one commits sin after being baptized, he should seek forgiveness from these transgressions in accordance with I John 1:7-9, not by being baptized repeatedly.
CASE #3: "Jed", after witnessing many of his friends be baptized, decided that he needed to do so also. He was immersed for the remission of his sins as an early teenager. He became unfaithful to God a short time after this. Later in life, Jed comes back to the Lord's church and expresses doubt about his baptism. He thinks the primary motive behind his baptism was not to obey the gospel, but to do what his friends were doing. He cannot put this doubt to rest so he, to be on the safe side, is immersed again. I do not believe there is anything wrong in a rebaptism in this case, though we may not be able to ascertain if it is necessary or not. Again, if there is doubt, it is always best to pursue the course of action that removes the doubt, where possible.
After the twelve were baptized in the name of the Lord Jesus, Luke records the following:
"And when Paul had laid hands on them, the Holy Spirit came upon them, and they spoke with tongues and prophesied. Now the men were about twelve in all. And he went into the synagogue and spoke boldly for three months, reasoning and persuading concerning the things of the kingdom of God. But when some were hardened and did not believe, but spoke evil of the Way before the multitude, he departed from them and withdrew the disciples, reasoning daily in the school of Tyrannus. And this continued for two years, so that all who dwelt in Asia heard the word of the Lord Jesus, both Jews and Greeks" (Acts 19:6-10).
After the twelve men were baptized properly, Paul proceeded to lay hands on them in order to enable them to work miracles by the power of the Holy Spirit. Specifically, these men were able to speak in foreign languages they had never studied before and prophesy. Afterward, Paul was able to continue teaching in Ephesus for about two years. Initially, he was able to teach in the synagogue, until too much resistance arose from the unbelieving Jews. Afterward, he was able to teach in a more peaceful environment in the school of Tyrannus as he further edified the disciples and evangelized Asia. When one door of opportunity closed for Paul, he always looked for another one that was open!