This is a restriction imposed by the operating system to prevent background recording for security and performance concerns. You may configure how long it takes for your iPhone to automatically lock if you require the screen to remain on for a longer period of time.
Check out https://support.apple.com/guide/iphone/keep-the-iphone-display-on-longer-iph7117338a8/ios for more information.