It depends on your sightseeing priorities. Basically, day tripping from one side of the peninsula to the other is suboptimal (though thousand of people do it everyday.) In a straight choice, I’d stay in Amalfi. To see the Amalfi Coast properly, I think you need to stay ON the coast. Literally all the traffic on the road are people day tripping in and then out. Avoid that melee and your stay will be a dream. Day tripping to places like Positano or Ravello are a relative breeze from Amalfi.
Sorrento is best if your sightseeing plans include Naples/Pompeii/Herculaneum. If it does, then it’s probably worth splitting those 5 nights. While I enjoyed my day in Capri, I didn’t feel like I was missing out by not staying there. And day tripping off Capri would be a total drag.