To trace, investigate, and find the Service Principal ID, go to Azure Monitor -> Activity Logs and check for operation Create or Update Network Security Group
To find the App ID that triggered this, go to Azure Active Directory -> Enterprise Applications (Yes, you pointed it right, automation scripts could cause this)
Check if the IAM role is properly assigned (Role misconfiguration could cause this)
Once UEBA is enabled in Microsoft Sentinel, examine the entity mapping and investigation graph to identify any anomalous behavior. (Compromised credentials could cause this).