WordPress suddenly starts uploading media to an old (backdated) folder

In case anyone encounters this in the future: after drilling down into the WP source and the database, it turns out that when media files are uploaded, WP still needs to attach them to some post, and for some reason, even though the post_id is 0 in the fuction which processes media uploads, it managed to find an entry in the wp_posts table and use that to attach media files to. After that, the mechanism which determins the path to save the media file based on the post it’s attached to kicks in, so the file is saved in the folder of the post entry.

I solved this by deleting the entry in the wp_posts table, after which WP stopped attaching media uploads to post entries, and storing them in the folder structure based on the date of the upload (i.e. the current date).

This took instrumenting the WP source and drilling down into what happens in the database. Definitely seems like a bug, and definitely not solvable in a user-friendly way.