I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.
Issue:
The issue you're experiencing seems to be related to how the OAuth2 flow is being handled during the user provisioning setup for your custom application in Microsoft Entra ID. Although you've enabled the feature flag (feature.userProvisioningV2Authentication=true) to allow OAuth2 client credentials flow, but when you attempt to "Test Connection," it fails and uses the Microsoft Entra bearer token instead of the OAuth2 token as expected.
Solution:
Issue resolved by @Andreas Häber
If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information. Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.