This also happens to my Redmi Note 9S.
It happens with all current ROMs. I experienced it with global, indian and eu ROMs.
Its also random, it does not happen after x hours. Sometimes its just 1 hour, others is 7 hours, others it does not happen.
What I do:
I turn off the smartphone screen to sleep, with wifi on. AC connected.
I have some apps reading internet data every 2 minutes.
When I wake up, I see the wifi icon connected. But Internet doesn't work.
When I look at the apps, I can see that they stopped accessing internet at a random time in the night.
If I turn wifi off and on, internet works again.
It doesn't happen with wifi off and mobile data connection on.
I tried changing some values in dev settings. Also in battery settings. Nothing has worked yet.
With normal day usage, it can also happens, if the screen is off a few hours.
It not a router wifi issue. My old note 3 worked fine with the same wifi. My wife's redmi note 8 pro works fine too.
It can be something related to battery saving. But so far I have been unable to fix if.
It never happens with screen on, or with screen off for a few minutes.
So I dont think its a hardware issue, I think its software-related.