Ḥamd means praise and dhamm means blame. In yakun ḥamduhu dhamman, yakun is an incomplete verb, ḥamduhu its subject, and dhamman its predicate. The grammar presents the reversal of an expected reward into its opposite.
Wa-yandami adds the internal consequence: regret. This makes the maxim more than a statement about reputation; it connects a decision, its external reception and the agent’s subsequent evaluation of that decision.