Another method is to uninstall the package that provides the executable pk-command-not-found -- on my Rocky Linux 9 the command_not_found_handle looks like this:
command_not_found_handle ()
[[ ! -x '/usr/libexec/pk-command-not-found' ]] && runcnf=0;
'/usr/libexec/pk-command-not-found' "$@";
printf 'bash: %scommand not found\n' "${1:+$1: }" 1>&2;
So you can see that it's dependent on that /usr/libexec/pk-command-not-found executable.
On a Red Hat-like system, you can do this to find out what package it is and uninstall it:
# rpm -qf /usr/libexec/pk-command-not-found
PackageKit-command-not-found-1.2.4-2.el9.x86_64
# dnf remove PackageKit-command-not-found
This changes it system-wide, all users would be affected.
Oh, and 2>&1 is just bash file handle redirection. It literally means "send my stderr to the same thing as stdout".