Every time a miner exchanges crypto for RMB (like with Alipay or WeChat), China overall benefits a bit. Because Chinese banks (as you correctly stated) are not allowed to hold crypto and exchanges are illegal, what really happens is the crypto gets exchanged for foreign fiat (like USD) where exchanges are legal, which then gets exchanged for RMB, building up foreign reserves.
In the past, a lot of miners were "foreign investors" (likely other Chinese "nationals" rather than citizens) who lived abroad and would keep the exchanged fiat in foreign bank accounts, which _is_ harmful as they pay for electricity with RMB but get to keep USD. In recent years, a lot of local mining outfits are appearing, and because they ultimately need to spend RMB, the government has no problem with turning a blind eye to them.
Yes, it is illegal for Chinese banks to do transaction for cryptos, but it is still legal to transfer money to others in exchange for crypto (p2p). WeChat, Bank Transfer and AliPay all being available in exchange. Holding crypto is not illegal in China, also mining is not illegal.
I believe there are still a lot shady business going on for those buying cryptos with RMB. It is quite easy for Chinese to buy/sell crypto at the moment.
Actually the same happens in stock market. When Chinese companies go for IPO in the US, they will typically keep the fund in US, rather than bring them back to China to make it easier to do business in dollars without restriction of Chinese financial system.
The minors are not making USD for foreign reserves to be honest, they are mostly a way to transfer wealth out of the country (buying equipments and electricity and sell bitcoins abroad or not selling it at all). That's why China has banned its bank to do crypto related transactions and exchanges mostly. However, it is hard to enforce. You can find many exchange use Bank Transfer, AliPay and WeChat pay.
Owning Bitcoins are legal in China. Who knows once the digital RMB is out.