If your iPhone is running the latest iOS 17 version, open Settings -> Passwords -> Password Options and enable "Clean Up Automatically" to allow your iPhone to delete verification codes in the Messages and Mail app automatically.