How do deal with low self-confidence after a failed research rotation? In short, my third rotation research supervisor withdrew support on a Friday afternoon before my scheduled qualifying exam the following Wednesday. I had been rotating in the lab for about three months. He said that I did not have the cognitive ("critical thinking") or emotional abilities to be a PhD student. Apparently I was getting too much input from my postdoc mentor and the other graduate students, so he did not feel comfortable having me take the exam to possibly join the lab. (Even I were to pass, he would still "fail" me.) Because the lab is large, I was mainly supervised and received feedback from the postdoc. He maintained that I did good work throughout the rotation and was asking questions at an appropriate level for my experience. A staff scientist enjoyed working me as well and felt I was making appropriate progress. 

When it came time to present the written report to the PI before the qualifying exam (which already had been approved by the postdoc) he was not pleased and could not believe that my postdoc mentor had approved it. He maintained that I would be absolutely picked apart by the committee for various errors. I needed to apologize and say how stupid it was to appease him. I asked other graduate students about his behavior, and they agreed he can be very condescending. I still felt uneasy though about the discrepancy in expectations between the PI and my postdoc mentor. 

While the PI was not supervising my daily activities, he knew of my personal struggles during my rotation. My medication for anxiety had been changed at the beginning of the rotation, and I was experiencing enough symptoms that he caught me crying during a meeting. I explained my diagnosis, and he was very kind and supportive and told me to let him know how I was doing. I kept him updated throughout the rotation, and maybe shared more details than I should have, but I felt I was safe because his wife is a mental health professional. I never shared to get sympathy. I just wanted to make sure he knew that I was trying my best, and I could sense my work was not up to my usual standards. I felt it was the responsible thing to do. Because I was not up to par for a few weeks, he asked for my rotational time to extend beyond the qualifying exam to make sure that we could work together. The uncertainty was hard to deal with, but older students in the lab assured me that he had never let someone go who had rotated that long. 

In the week before the qualifying exam, I moved and got diagnosed with an infection. The move provoked my anxiety, and the infection of course did not help, so I let him know what was going on because my draft edits were going to be late. That Friday afternoon, all of my problems that week, along with my mental health history in general, were used to substantiate that I was not emotionally ready for a PhD. 

Because my first rotation mentor was a poor fit, and my second rotation mentor lacked funding, the department gave me a fourth rotation. The lab I am in now aligns well with my goals. However, I cannot escape the feeling that I am not catching on soon enough and I'm making mistakes on topics I "should" know. I am very worried that this PI will kick me out as well when he finds out what I actually know. The negative thought is always creeping in that I am not good enough, and maybe the third rotation PI was right. Realistically, my previous two mentors did not sense any problems, and my undergrad mentor maintains I will be a good grad student. 

I'd appreciate any thoughts or advice. Thanks.
As suggested in a comment, ask your present PI to sketch out explicitly the goals for this rotation.  Take the initiative by writing a first draft, but ask the PI to help you refine your list.

Send the PI regular progress reports.

Try to find a support group.

It's fine to let a PI know of your diagnosis, but unless this person has personally demonstrated his or her trustworthiness, over a significant period of time, I suggest you draw some clear boundaries in your own mind, between what personal information you will share with a PI, vs. what personal information you will share with a support group or a therapist.

Read what I wrote about figuring out which educational accommodations would be helpful for you in this other answer.

Consider having a few sessions of EMDR about the specific trauma of the recent failed rotation.  Here is a link to get you started reading about EMDR: https://www.emdr.com/what-is-emdr/