Recently I saw an action movie about military police officer in the U.S. One question surfaced for me - as far as I understand main task of military police (including its investigators) is to combat crime inside U.S. army (and crime related to the army). On the other hand, as far as I remember almost in every country, including U.S., army cannot be used on the domestic territory for pretty much any operations. As I understand, military police is part of the military and technically any investigation or operation which military police will perform would be a violation of this ban on usage of army in homeland.
How this paradox is resolved from legal perspective? Am I misunderstanding something?