An extension of the Bourgain-Sarnak-Ziegler theorem with modular applications