I'm a little rusty on what exactly causes this, so I've dug up my reply from another thread on this topic:
I had a support ticket from a guy using Retro Pie with the Unicorn HAT a while ago- it turns out that the two most definitely don't play well together. The Retro Pie initialises some sound drivers which completely garble the Unicorn HAT output and make it basically impossible to use once you log in.
It's possible to fix, but the fix is to prevent Retro Pie launching on login- which is kind of counter-productive when your goal is retro gaming.
The fix is generally "use HDMI audio so it doesn't conflict," but I don't recall this working on RetroPie as it should. I don't know if this is something that can be raised with the RetroPie team, since the system shouldn't be doing anything over analog audio if it's set up to output via HDMI.