You are making the mistake of looking at part of the molecule instead of the whole. Let's look at your example involving esters, or better yet carboxylate ions. You have the carboxylcarbonyl group and then a second oxygen atom. When the latter donates its pi electrons to the molecular orbital, they go into an antibonding orbital of the carboxylcarbonyl group. So that part of the bonding is weaker. But this interaction also makes a new pi bonding interaction involving the second oxygen atom. You have to count that, too, to evaluate the bonding in the whole molecule. When the extra bonding outweighs the extra antibonding in the whole molecule, as in pi electron delocalization in an ester or carboxylate, the interaction is favored even though not every part of it is.