This might be helpful:
https://askubuntu.com/a/1350429
Under WSL2, the entire filesystem is kept in a virtual HDD file named ext4.vhdx. You can find it in %userprofile%\AppData\Local\Packages\CanonicalGroup...\LocalState\ext4.vhdx. The ... part will vary depending on the exact Ubuntu version you installed from the Store.
Back up this file before reinstalling Windows. Make sure WSL is not running at all via a wsl --shutdown (assuming you can still access that command). If you can't wsl --shutdown, at least reboot Windows before backing up the file, to make sure it is not in use. You could also run in safe mode, if you really want to be sure.