This is related to the OSX/Pirrit thread from here. After two days of debugging and visiting Apple stores, I eventually erased all data on the disk and migrated my files later with Migration Assistant. It's fixed now! However...
I can't use my old username! If I rename the home folder to that one, the pervasive error shows up again. It's really annoying.
I'm not sure if this is some kind of malware, as I ran the command indicated by @klanomath:
dscl . -list /Users UniqueID | grep 401
And nothing was printed in the console, thus this shouldn't be OSX/Pirrit. What might it be then?
Running High Sierra 10.13.5 on a MacBook Pro Late 2016.