During trying to determine the exact conditions of the error, I started anew with a fresh .emacs.d folder and reinstalled my packages, and the bug disappeared. I guess an earlier version of Emacs (in which that related bug was not yet fixed) wrote something in .emacs.d that set the wrong encoding. I still have the old .emacs.d if we want to investigate further.