Try booting into Safe Mode to see if you have the same problem. I'm not sure if you will be able to use the camera while booted into Safe Mode, but it is worth a try. Try using Photo Booth to see how the camera behaves in Safe Mode.
You can try creating a new macOS user account. Log out of your main user account, then log into the new macOS user account. If the new user account has the camera working fine, then most likely you have a login item causing a problem, or maybe a configuration issue or corrupt .plist preference file in the main user account.
If you still have issues while booted into Safe Mode (or you cannot use the camera in Safe Mode), then Create a new APFS volume, making sure to give it a unique name such as "SonomaTest". Then install macOS Sonoma onto the new APFS volume. During setup, just create a new macOS user account. Do not migrate or restore from a backup and do not sign into your AppleID. Do not install any software. Do you have the same issue with this new install of macOS under these conditions? If not, then most likely you have some third party software installed on the original OS volume which is causing a problem. Before deleting the new APFS volume, make sure to first change the default Startup Disk back to the original macOS volume (default name from the factory is "Macintosh HD").
If even the fresh install to a new APFS volume still has the camera problem, then your only remaining option would be to try a DFU firmware Revive which resets the security enclave chip & system firmware. While this should not affect your data, you should still make sure to first have a good backup since a hardware issue could prevent the DFU firmware Revive from completing which could cause you to lose access to the data on the internal SSD. People should always have frequent & regular backups anyway since there are a lot more new ways to permanently lose access to data on an internal SSD with the newer Macs due to all the hardware, software, and security changes.
You can try running the Apple Diagnostics to see if any hardware issues are detected.
Edit: Also, try disconnecting all external devices in case one of them is causing a problem.