Babies certainly did not evolve to waste valuable time and resources on crying nonstop for no good reason, they likely do so only because something is not quite right. A more optimistic take is that they do it to develop the pipes, and the nonstop crying will pay off later with a great voice.
And there are sources of colic that have nothing to do with digestion - a quick perusal of WebMD lists noise/light sensitivity, nervous system misfires, and baby migraines (poor babies)!
Colic certainly might be an indicator that something is not quite right, but that doesn't mean there's always something you can do about it. As I write this with my exhausted newborn son sleeping in my arms, sometimes you just have to wait for them to grow out of it.
EDIT: I looked into this a little more since I'm pinned by a sleepy baby and as with everything with babies it's complicated. Here's a study that shows that formula-fed babies cry more at 2 weeks than breast-fed babies, but less at 6 weeks: https://pubmed.ncbi.nlm.nih.gov/10193923/
This is probably also hindered by the fact that "colic" is an imprecise term - all babies cry, but at a certain point if they cry enough you call it "colic".