Is it safe to charge a DeWALT 18v battery if the charger emits a whining noise
It's possible that the battery's days are numbered, but I doubt that the whine you're hearing comes from the battery itself.  That noise is called "coil whine" and comes from the windings of the transformer(s) inside the charger.

An electrical engineer (which I am NOT) could probably explain why you get the noise with one battery and not the other; I can only speculate that the charger is having to crank up the voltage a bit to force a charge into that one.  If that's the case, it could mean that the battery is on its way out, but in any case I wouldn't worry that it's going to blow up.