Use parameter expansion:
#! /bin/bash
strings=('Job with id 0 ended with status COMPLETED, return code 16, in 1 minute 12 seconds'
'Job with id 0 COMPLETED with return code 255'
)
for string in "${strings[@]}" ; do
code=${string#*return code }
code=${code%,*code%%[!0-9]*}
echo $code
done
# removes pattern from the left, % from the right.