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.