Problems with Page Not Found

So yes, the key point here is that you should put the WordPress-specific 404 template file in the theme directory (e.g. wp-content/themes/your-theme/404.php) and not in the root WordPress directory.

And despite that you already got the solution, I thought you would still want an answer to the following?

I would like to figure out what causes the long posts page to display
sometimes instead of the “Oh no” message.

So in a default WordPress setup with %postname% as the post permalink structure, the first two requests (/a/b/test.gif and /a/b/c/) do not match any of the (saved) WordPress rewrite rules, hence a 404 error is issued, but WordPress would still query the recent posts on the site — and this query is what we call as the main (WordPress) query.

And when the WordPress-specific 404 template is not available, the default index template (index.php) is used and therefore you’d see the long posts page because the index template normally displays posts from the main query mentioned above.

But the other two requests (/a/test.gif and /a/b/) matched an attachment post request (i.e. there are rewrite rules for those requests/URLs), so WordPress would try to find the attachment post (test-gif and b respectively), and if not found, then the “no content” message would be displayed instead. See have_posts() and this part in Twenty Twenty-One’s index template.

So the rewrite rule defines the query and the query determines the template that should be used, and index.php is the default template used when all other matching templates (404.php, category.php, etc.) are not available — see the WordPress template hierarchy for more details.