The practice of racial profiling in these sorts of situations is typically justified through an appeal to the need for national security. In WWII, there was also more of an overt racial aspect to the justifications for the profiling.
The major justification used in both cases was the idea that profiling was necessary in order to maintain national security. The idea was that profiling would be more likely to prevent further attacks than an attempt to identify individuals who were likely to help the enemy. At a time of grave danger and crisis, it would simply be too difficult to try to identify individuals threats and so it made more sense (in some people’s minds) to focus on the groups that were seen as most likely to aid the enemy.
At the time of WWII, racial attitudes in the US were much less enlightened than they are now. Therefore, at that time, there was also a racial justification used. Some people argued that Japanese as a “race” were innately untrustworthy and therefore needed to be rounded up to prevent them from acting in accordance with their nature.
The major justification for these kinds of profiling is national security.