The Role of C/O in Nitrile Astrochemistry in PDRs and Planet-forming Disks