Dr. Monzer Kahf, a prominent economist and counselor states: As a striving muslim, If we find ourselves working in the army but not directly involved in killing or aggression acts against the rights and freedom of other people, including occupying Afghanistan and Iraq for example, then the salary is InShaAllah Halal and we can use it to go for Hajj. But if a muslim is a part of an occupation/aggression battalion, the work itself is Haram and the salary earned is equally Haram and one must not use it to go for Hajj.”
Allah Almighty knows best.