I had to revise and test the script to exclude the parent directory name from the renamed filename, so output looks like it did previously:

This came with a time price as the Zsh script in the Terminal worked fine and Automator threw a wrench into the result. So fixed the Automator result per the above tree diagram.
Code:
#!/bin/zsh
: <<'COMMENT'
Rename every file in the selected parent folder hierarchy with the prefix
string of the sub-folder hierarchy to the file punctuated by underscores. The
parent directory name is removed from the path string comprising the new filename.
Multiple runs do not process previously renamed files in the parent folder hierarchy.
Reference: https://discussions.apple.com/thread/254456435
Example:
Job1/Brand2/Personae1/FR/Animated/300x250.zip => Brand2_Personae1_FR_Animated_300x250.zip
Usage: Used as a Quick Action, select one or more parent folders in the Finder.
Tested: Zsh 5.8.1 on macOS 13.0.1
VikingOSX, 2022-12-11, Apple Support Communities, No warranties at all.
COMMENT
typeset -gi stime=0 etime=0 elapsed=0 parcnt=0 fcnt=0
function finished () {
osascript <<-AS
use scripting additions
display dialog "Parent folders: $1" & return & "Files: $2" & return & "Time: $3" with title "Processing Complete"
return
AS
return
}
function elapsed_time () {
local secs=$1
# output is 0d:0h:0m:0s format
# https://unix.stackexchange.com/questions/27013/displaying-seconds-as-days-hours-mins-seconds
echo $(($secs/86400))d:$(($(($secs - $secs/86400*86400))/3600))h:$(($(($secs - $secs/86400*86400))%3600/60))m:$(($(($secs - $secs/86400*86400))%60))s
return
}
#start time
stime=$(date -j -u +%s)
# permit case-insensitive file and folder name treatment
setopt nocaseglob
for parent in "${@}";
do
(( parcnt++ ))
for subfolder in ${parent}/**/*(.N);
do
# skip files already beginning with subfolder and underscore in their names
[[ "${subfolder:t}" =~ "^.*([_]+).*$" ]] && continue
# get $HOME and parent folder
trimP="${subfolder:h5}/"
# remove $HOME and parent folder name from new filename using trimP pattern
ppath="${subfolder#${~trimP}}"
# change '/' to '_' in new filename
fpath="${ppath:gs/\//_/}"
mv "${subfolder:h:r}/${subfolder:t}" "${subfolder:h:r}/${fpath}"
(( fcnt++ ))
done
done
# end time
etime=$(date -j -u +%s)
elapsed=$(( etime - stime ))
# only show finished dialog when new files have been processed
(( fcnt )) && $(finished ${parcnt} ${fcnt} $(elapsed_time $elapsed))
exit 0