It's frustrating when your iPhone doesn't ring when it's locked, right? There are a few things that could be causing this.
Sometimes, Do Not Disturb might be accidentally turned on. This silences calls and notifications, even if your phone is unlocked. You can check this by going to Settings > Focus > Do Not Disturb.
Another possibility is that "Silence Unknown Callers" is enabled. This feature silences calls from numbers not in your contacts. You can check this in Settings > Phone > Silence Unknown Callers.
Try restarting your phone