How to grant badges using Automation?

For that you would need to enable custom SQL badges, which isn’t available to everyone depending on their hosting:

Though using the API is also suggested as an alternative.