Here: https://github.com/docker-practice/actions-setup-docker/blob/fd7ecdac7caf8e2c541a48c9bcc280aae59a8461/lib/setup-docker.js#LL290C91-L290C91
The last sudo makes sure cat is run with root privileges but not the redirection of the output >. Reproduce:
(run as non-root user)
$ sudo echo "test" >/usr/share/keyrings/docker-archive-keyring.gpg 
bash: /usr/share/keyrings/docker-archive-keyring.gpg: Permission denied
# but this works
sudo sh -c 'echo "test" >/usr/share/keyrings/docker-archive-keyring.gpg'