execute action on workflow transition
You can use hook_ENTITY_TYPE_update to achieve this.

/**
 * Implements hook_ENTITY_TYPE_update().
*/

function mymodule_node_update(Drupal\Core\Entity\EntityInterface $entity) {

    //Get the current Moderation state;
    if (isset($entity-&gt;moderation_state) &amp;&amp; isset($entity-&gt;moderation_state-&gt;getValue()[0]['target_id'])) {
        $currentState = $entity-&gt;hasField('moderation_state') ? $entity-&gt;moderation_state-&gt;getValue()[0]['target_id'] : null;
    }
    //Get the original Moderation state;
    if ( isset($entity-&gt;original-&gt;moderation_state ) &amp;&amp; isset($entity-&gt;original-&gt;moderation_state-&gt;getValue()[0]['target_id']) ) {
        $originalState = $entity-&gt;original !== NULL ? $entity-&gt;original-&gt;moderation_state-&gt;getValue()[0]['target_id'] : null;
    }

    #Get the Transition;
    $workflowTransition = rtrim($originalState.'--&gt;'.$currentState);

    switch ($workflowTransition) {
       case 'published--&gt;needs_review':
       case 'draft--&gt;needs_review':
       //Do something.
      break;
       case 'draft--&gt;needs_review':
      //Do something else;
      break;
    }
 }