Modulo the differences in kids and situations: I’ve seen timeouts intended as punishments and I agree they typically don’t work (not that punishment “works” particularly well either).
But it can be great as a way to defuse a situation when the participant(s) is/are amped up to the point where they can’t think rationally can not only be useful but be welcome. Adults do this too: they get angry or ovwrstimulated and take a walk to “cool off”. Kids can get amped up by all sorts of emotions, not just anger (which appears to be uncommon in most young kids).
As for punishment: I think it’s mainly for the benefit of the one administering it (something that also carries through to the criminal “justice” system). However facing the consequences of your actions is useful (when the milk spills in your lap you need to change your clothes because sitting in wet sticky clothes is no fun either...so learn. It to spill things). And as kids get older (8+...?), their requirements become more abstract so can the consequences as well. But ideally still connected to the infraction.