Two keys on keyboard suddenly switched roles
Solution 1:
When a new keyboard is connected, macOS will show the Change Keyboard Type
button in System Preferences > Keyboard. This is used to detect the type of keyboard. For mine, it would have had to be ISO, but it seemingly got wrongly configured in the past, and the button would not show.
Deleting /Library/Preferences/com.apple.keyboardtype.plist
and rebooting made the button reappear and I could set up the keyboard correctly again.