I find it hard for this answer to not be:
It depends on the professor.
However, do not listen to the imposter syndrome. Focus on your accomplishments, not on perceived failures. So you did not get into program A. The reasons you did not get into program A could be anyone of a long list of unknown and unknowable factors that have nothing to do with you. The number of applicants to program A may be so large that you were not excluded because you were not up to snuff but because you were one of a large number of very qualified applicants. Maybe the chair or members of the admissions committee are lazy, negligent, or perhaps just overwhelmed - and thus your application was not even examined. Perhaps your application was lost by the bureaucrats before it ever got from the dean's office to program A. Think no more about program A.
You did get in to program B. Focus on success at program B. The professor you wanted to work with moved from program A to program B, so there must be something better about program B. Consider the fact that you were accepted at program B and that the professor you want to work moved from program A to program B to be indicators of a good chance of success at program B.
The only way that working with this professor will not happen is if you don't pursue it. If you worry yourself out of trying, you guarantee your failure.
Unless that professor was on the admissions committee, there is a fair chance that professor may not have even be aware of your application to the other program. Even if that professor was on the committee, he or she may not even remember you. Depending on the school and/or discipline, there may be hundreds of applicants. Even if that professor knew about your previous application, he or she should be professional enough to ignore it. If not, then maybe you don't want to work for that person.