It is possible to justify racial profiling in these sorts of cases by arguing that the good that comes from the racial profiling outweighs the wrong that is done to innocent people who are persecuted on account of their race.
In both the 9/11 attacks and the attack on Pearl Harbor, reasonable people could have felt that America was in serious danger. The fact that the Axis was winning the war as of December, 1941, coupled with the effectiveness of the Japanese attack on Pearl Harbor made the US seem to be in danger. The magnitude of the 9/11 attacks, coupled with the fact that there are “soft targets” all over the United States could make it seem as if the US could be vulnerable to multiple attacks.
In addition, reasonable people could believe that America was in danger from specific groups of people. Reasonable people could have felt that the people of Japanese descent in California were a potential “fifth column” for the Japanese Empire. Reasonable people could have felt that Muslims in America were more likely sources of terrorist attacks than African Americans or Hispanics.
With the situation (arguably) being this serious, racial profiling can (arguably) be justified. The harm done to innocent people can be seen as an acceptable price to pay for preventing serious harm to the United States.