For anyone who's like me been searching for a way out of this absurd situation. The solution is to force quit the 'installed' process from the activity monitor. It's a root process and only quitting it won't work, you have to force quit it.
This effectively stopped the never ending loop of "installing" Xcode. It's now back to the cloud icon of redownloading in the app store.
It's insane that this is an official Apple product (their main development platform) and it's bugged at the very early stage of installation (bugging your whole system in the process, by pegging the CPU cores endlessly). Oh and mind you this is on the latest 14" M1 Pro MacBook Pro (again, their own hardware) with the latest version of Monterey at the time of writing this comment.
When people told me Xcode is giant mess of bugs and frustrations I didn't believe them. Well, now I most definitely do.
Moral of the story: don't install Xcode from the App Store (or don't install it at all if you can afford).
UPDATE: after going through this whole process, if you want to redownload Xcode from the App Store (I did try it) you can, and the spinning wheel was there again. But this time it resolved after a few minutes and the application was successfully installed. But I purposely tried to keep the laptop awake the whole time. I think if your laptop goes to sleep in the middle of this process, it causes the installer to bug and spin indefinitely.
FWIW, I have the same problem and I am working with Big Sur (11.6.1.) on an intel-based system. So I don't think the problem has anything to do with Monterey or the M1 chipset.
For me, it's hanging at about 97% complete. I'm unable to stop the install/upgrade (I did have the prior version already installed on this laptop). A reboot of the system had no effect on the problem.
Same on a 2020 Intel MB Pro 13" on MacOS 12.0.1. Tried uninstalling Xcode (worked for me in the past with similar issues with apps installed via the App Store) but now the App Store still shows it partly downloaded.
Intel-based Big Sur here with same issue. I installed another app at the same time and it hung as well. After rebooting, the other app said it was done but Xcode was still hung.