NginX's configuration is declarative.
The reason the imperative if was given powers beyond its means was because people clamored for the feature.
The reason it's still there is because removing it would break some working configurations that use if.
If you don't have experience with declarative programming and you think in terms of imperative programming, it might seem "horrible behavior", but actually, it's what is to be expected from mixing the two paradigms in the way it is being mixed.
The real wart is under the hood where-in location based if's are converted to sub-locations. This is where many problems related to IfIsEvil stem from.