I’ve had that happen too. From what I can tell, the game just flips control to whichever player has the stronger influence or more “claim” ships hanging around. If both you and your ally keep capital ships in range, it keeps bouncing ownership back and forth.
Easiest fix I’ve found is to either pull your ships out after the capture or coordinate so only one of you keeps a cap ship close. Otherwise it just turns into a tug-of-war. Not sure if that’s intended behavior or a bug, but it definitely feels odd when it happens.