Welcome to the club of camera malfunction. I tell you it's not hardware issue, it's software. It happens to me, and comes and goes, depending on what I do with the OS configuration. As I don't remember what I did last time to fix it I can't help you but at least I assure you it's software related, I can't say it enough because I am so tired of it.
As I have to wipe out my phone for some camera unrelated reasons, I know it will work after the fresh install but I am also sure it will start behaving like this eventually, every single rom I've tried in the past for different phones have failed with something, and no matter how "stable" they were that when something fails it fails forever regardless of the amount of revisions, updates or OS upgrades, it will fail.
So my suggestion is, either learn to live with it or change the OS completely to a different one that fails with something you don't care about.
P.S: Sorry to reply after a year, but the OP seems that is still having the issue as no solution was given :(. Btw, my phone is Pixel 6a.