I don't think it is as simple as "get a grip", "have harsh words with yourself", "tell yourself you are behaving unacceptably".
When I first got pregnant I developed irrational feelings against a close friend. I felt I needed to get away from her because I didn't want her near my baby when she was born. I felt SCARED of her being near my baby.
When I was pregnant the second time I developed similar irrational feelings against my MIL but worse and lasted longer after DS's birth.
For me it was a control issue I think. I already had issues to do with feeling not in control of what happens to me/what happened to me as a baby and as a child before I had my children. I feel protective towards my children to the point of anxiety which sometimes exhausts me and still makes me irrational.
My friend A had been talking about another friend of hers B who had recently had a baby and how her friend didn't know what she was doing but A just picked up the baby and got her to stop crying and gave her a bottle and she was Oh so good at it and better with the baby than his own mother B. A is very confident and likes to take control and be in charge of organising people (I am NOT this confident). I love her but recognise that she feels desperate to be needed and can be manipulative - manipulating her way into a 'needed', 'in charge' position.
My MIL also feels desperate to be needed and in charge, even more. She still treats her adult sons as children and encourages them to think they can't do things for themselves and need her to do it for them. When I had children (I was the first DIL to do this) she seemed to struggle with not being the No 1 Mummy any more and tried to interfere and take charge and force herself into an important needed role. She is also an assertive person (I am NOT).
Thank you if you have read this far, I know I am a waffler. It is background to this fact - I was scared they would take over and take my baby (emotionally) away from me. I knew I would be nervous about my ability to form a bond with my baby and would need time and space to do it and didn't want overconfident people marching in taking the baby off me (in a let me have a go I'll get him/her to stop crying kind of way, or a don't do it like that, I'll show you how it's done kind of way) and making me feel rubbish at it. The mother's bond with the baby is the MOST important thing and should not be interfered with so people need to be aware of giving the mother space. This bonding issue is probably a sore point for me after being taken from my birth mother then temporary foster mother then put with cold unexpressive adoptive parents, but I bet lots of mental health experts would say that a baby's bond with it's mother (or not) has a HUGE effect on their mental health into adulthood.
There is also the fact that I wanted to be the important one for once in my life and didn't want other people taking this from me. I finally had someone in my life who was my flesh and blood who I was determined to have a normal healthy relationship with. I hadn't had that so far so wasn't going to let anybody take that away from me.
I have a relative who is still quite possessive over her children and I think she is like that because she has lost several family members and is desperate to keep hold of her children.
I'll stop going on now, just saying reasons why I know it could happen in case any of them apply to you, OP and could help you understand yourself.