A logic issue was addressed with improved checks. This issue is fixed in macOS Monterey 12.6.2, macOS Big Sur 11.7.2, macOS Ventura 13. An app may bypass Gatekeeper checks.
https://support.apple.com/en-us/HT213534
https://support.apple.com/en-us/HT213533
https://support.apple.com/en-us/HT213488