When plugging in a new keyboard to the Mac you need to set what kind of layout it has if not detected automatically. The Keyboard Setup Assistant usually pops up the first time you plug the keyboard in and you can choose if it's ISO or ANSI. Sometimes the type can be reset for some reason and you need to run the assistant again to select the layout. Like in this case when my Swedish keyboard was reset to an ANSI layout.
This can be solved by running the assistant again but if you're unlucky macOS has decided that you don't need to change the layout if you've used the keyboard long enough. The button to trigger the assistant is missing.
To remove the saved layout for the current keyboard just run this command to remove the keyboard preference plist.
sudo rm /Library/Preferences/com.apple.keyboardtype.plist
After this you need to restart the computer and when logging back in you should be greeted by the Keyboard Setup Assistant.
If not you should be able to see the button for triggering the setup manually under
Settings -> Keyboard -> Keyboard.