I'm a little confused, so let me clarify.
You say that when you are bottoming, you lose your erection, then if your partner pulls out, you're immediately erect again? When your friend tops, he can't stay hard?
After your partner is fully inside, do you get your erection back? Have you tried using your hands/your partners hands to get it back? Does it happen with toys?
Just like with most things, every person reacts differently. Not every man can maintain an erection through anal sex. A lot depends on the sensations - too much, too little, if there's pain (and I know there doesn't have to be pain, but if prep isn't done well enough, there can be), etc.
Physically, not every man will get an erection from anal sex. If you lose the erection while being penetrated, and get it back when you aren't, it might be something with the vagus nerve, which is tied to blood pressure. If your blood pressure is low, it might make it difficult to maintain an erection when your vagus nerve is involved.
I did a quick google search on this, and there are a lot of threads about this on Reddit. I'd guess about half of the men who responded, maybe more, said they have the same experience.