Marvel's history with the military has fluctuated from film to film. All three Iron Man films received official military support. While the movies do involve critique of American foreign policy in regards to weapons manufacturers, the picture of the military itself was flattering enough for the film to gain access to Air Force planes and accurate costuming. As one would expect for a patriotic World War II film, Captain America: The First Avenger also received support from the U.S. Army as well as the British Ministry of Defense.
Where Marvel and the military became conflicted was during the production of The Avengers. The military was involved in the production initially, and Hollywood's Pentagon liaison Phil Strub is thanked in the film's credits. However, late in production, someone in the chain of command ultimately took issue with S.H.I.E.L.D.'s vague, extra-governmental powers.
"We couldn’t reconcile the unreality of this international organization and our place in it," Strub told Wired. "To whom did S.H.I.E.L.D. answer? Did we work for S.H.I.E.L.D.? We hit that roadblock and decided we couldn’t do anything."
If S.H.I.E.L.D. might have seemed too sketchy to the Pentagon in The Avengers, it's interesting that the Department of Defense was back on board for Captain America: The Winter Soldier, wherein S.H.I.E.L.D.'s powers are even more extensive and morally objectionable. The film's extremely harsh in its political commentary, yet oddly enough that extreme harshness might have been what brought the Pentagon back.
The reveal that Hydra infiltrators have taken power in S.H.I.E.L.D. and the U.S. government might reflect poorly on said organizations, but it also could be read as absolving the "real Americans" of their crimes by pinning the blame on a separate, evil group. It's this latter reading, combined with Steve Rogers and Sam Wilson being such positive portrayals of veterans, that earned Winter Soldier the department's approval.
Since Winter Soldier, though, Marvel's mostly avoided major military collaborations on its movies (though its comics division encountered controversy for almost working with military contractors Northrop Grumman). Age of Ultron and Civil War kept much of their big action set pieces outside the United States, while there's not much the military could do to assist on sci-fi films like Guardians of the Galaxy and Thor: Ragnarok.
It makes sense why Marvel would choose to again team with the Department of Defense in a major way for Captain Marvel, a film where the main heroine is an Air Force pilot. That Marvel was willing to stick to its guns on The Avengers and managed to work in some anti-establishment messages into Iron Man and Winter Soldier would imply that the studio is concerned more with telling the stories they want to tell than specifically serving as military propaganda.
That said, it is important for viewers to be aware that these military collaborations exist so they can better engage with the messages presented in their media.