Are you re-calling the entire code snippet above every time you capture a photo? According to the docs, you don't need to re-Initialize each time - https://video2.skills-academy.com/en-us/windows/uwp/audio-video-camera/basic-photo-video-and-audio-capture-with-mediacapture#capture-a-photo-to-a-softwarebitmap.
Also, you can refer to this sample, it works well in my test - Windows-universal-samples/Samples/CameraStarterKit at main · microsoft/Windows-universal-samples · GitHub.