In this specific case, no, you probably can't prevent this from happening. Assuming a best case when laminating drywall to existing lath and plaster, it is screwed in place and all screws penetrate into studs. Bottom line is that it's a tough thing to do, and a lot of fasteners end up just biting into wood lath. Nails are not only not the best idea for this application, but they can do some damage since any banging on old lath and plaster walls tends to knock "keys" off the back side of the lath. Keys are just the portion of the first coat of plaster that oozes through the gaps in the lath and forms a "hook" that holds the whole assembly together. Once you bust enough keys, plaster comes off in big sheets, and sometimes a layer of drywall is the only thing holding the whole mess in place, LOL. When you are screwing your new shelves in, you a literally compressing the whole assembly (lath, three layers of plaster, and the drywall) Since the nailed drywall failed to really get the "sandwich" compressed tight, your screw causes the nail to pop. A full blown body slam on that wall would do the same thing. Bottom line, it's like floor squeaks, and other charms of old homes, just one of those things. Have fun.