The listing, Pokémon Sword and Shield: Ash's Pikachu Codes has ended.
All of Ash's various hats from over the years – so that's eight generations' worth – will become available in due time, starting with the iconic hat from the very first season of the show. In a nice touch, they'll also have 'Ash' as their original trainer in-game.
If you need help, here's how to use the codes:
Launch your Pokémon Sword or Pokémon Shield game.
Select Mystery Gift on the X menu.
Select Get a Mystery Gift.
Select Get with Code/Password to connect to the internet.
Enter your password.
Watch as the gift arrives in your game. (Pokémon will appear in your party or your Pokémon Boxes.)
Be sure to save your game.