[cli] allow to run `factoryreset` under the diag mode (#7566)

Before starting a test case, our test script calls the `factoryreset`
to make the device enters a known state . But the previous test case
may fail to call the `diag stop` before exiting. This case the next
test case failed to call the `factoryreset `.

This commit allows the users to call `factoryreset` under the diag
mode.
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp
index 3844d69..b159577 100644
--- a/src/cli/cli.cpp
+++ b/src/cli/cli.cpp
@@ -262,7 +262,7 @@
     LogInput(args);
 
 #if OPENTHREAD_CONFIG_DIAG_ENABLE
-    if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag"))
+    if (otDiagIsEnabled(GetInstancePtr()) && (args[0] != "diag") && (args[0] != "factoryreset"))
     {
         OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands.");
         ExitNow(error = OT_ERROR_INVALID_STATE);