Pakistan is a state held together by strings, simply taking a beating would greatly undermine its legitimacy and could make the entire thing unravel.
Winning a war against India is exactly what Pakistan needs to solidify its statehood, and as dangerous - and to some extent utterly insane - this may be; it could very well be the only viable course of action as India will no doubt continue to seek the demise of Pakistan. It all comes down to how much support Pakistan can get from China. And while India may have the blessing of the US/NATO, at the very least they aren't currently in a strong position of aiding India.
For China, finding a reason to turbocharge its military industrial complex isn't necessarily a negative.
I'm partial to the cope theory that if India is humiliated too hard, all sides lose.
Actually doing painful reforms that gives them long term benefits.
HAL being not useless in 20 years,
Maybe swallow their pride and get F-35s somehow.
or other major geopolitical realignments etc.
Status quo here means they learn little yet again once the shame of losing a shiny Rafale in a blotched op goes away.
2019 on repeat.