Normally when running the php command, the php-cli wrapper picks up the PHP version that is configured in the working directory throught the .htaccess file. When running composer, the system default is used instead:
# grep AddHandler .htaccess
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
# composer diagnose
PHP version: 7.0.33
This issue is caused by composer using /opt/cpanel/composer/bin as its working directory. An improvement case is currently open to see if this can be improved. The case ID is CPANEL-23228.
Either use SCL or full path to the binaries involved.
scl enable ea-php74 'composer diagnose'
/opt/cpanel/ea-php71/root/usr/bin/php /opt/cpanel/composer/bin/composer diagnose
ea-php74 /opt/cpanel/composer/bin/composer diagnose
Further troubleshooting for composer can be found here: