After successfully thwarting off attacks by pirates or CPU opponents, I found that sometimes if I went to manually move my remaining ships into a custom formation in the gravity well, that some ships would attempt to make a jump to a random planet in my empire (typically a nearby node, sometimes back to my capital). This happened maybe 10 times over the course of my game. I would randomly stop their actions, try again, and it would repeat itself. After a couple of minutes they would act normal again when moved manually to different parts of the gravity well. And I was close enough viewing the gravity well that I definitely didn't do it by accident by clicking a planet on the empire tree.