The hat is located in a weapons depot on the last chapter of Mission 12 (where you have to destroy those 8 yellow markers on the ceiling right before facing Shadoon). If one of your characters dies ...