Place your anti-forgery middleware after the UseStatusCodePagesWithReExecute and it will work (tested on .Net 9) :
app.UseStatusCodePagesWithReExecute("/404"); app.UseAntiforgery();