Was it illegal to loot in WW2? Well yes and no
Legally speaking you could take military equipment, like pistols, rifles or even flags. In fact the US had a whole bureaucratic process to help soldiers mail these trinkets home as seen with these certificates for a luger souvenir or this one for a japanese sword
However, even then it was both against military regulations and international law to take personal belongings being classed as pillaging, although many still did. So taking rings, diariesand watches was technically a war crime.
However, possibly the most common type of illegal looting was that of food and booze. Taking anything from civilians is strictly illegal and yet who's going to stop a GI with a rifle from taking a bottle of wine or two or stealing farmer's produce.
The truth is unless you looted something outrageous you were unlikely to get prosecuted as one of the allies even if caught. One of the only and most high profile cases of actual prison time for looting was that of three officers who stole diamonds, jewelry and more from a princess in Germany. But when you’re taking that much you kind of deserve to be caught.