Energy optimization in extrasolar planetary systems: the transition from peas-in-a-pod to runaway growth