Fix middleware 404 prefetch case (#46782)
Ensures we properly generate the 404 page when a path is being prefetched with middleware configured.
## Bug
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
Closes: https://github.com/vercel/next.js/issues/38239#issuecomment-1454928413