Script to move images into year and month folder
I see this invocation of stat is MacOS specific.

Here's how I would shrink your code

find . -type f -iname '*.jpg' -size +500k -exec sh -c '
    for file in "$@"; do
        folder="/path/to/backup/folder/$(stat -f '%Sm' -t '%Y/%m' "$file")"
        mkdir -p "$folder"
        echo mv "$file" "$folder"
    done
' sh {} +


mkdir -p will create all missing folders, and it will also suppress errors if the directory already exists. 

find's -exec cmd {} + feeds several filenames to the given command.

And this looks odd sh -c 'stuff' sh file ... -- the 2nd sh will be assigned to $0 inside the -c script, and the given files will be $1, $2, etc.