When installing two layers of subfloor, is it okay to secure both layers to joists?
That's the usual approach. Almost no one puts down double-thick subfloor in residential applications (for cost and handling reasons), and both layers need to be fastened to joists. Only thin underlayment can be fastened just to the subfloor.
I'm not sure what your question about tile means. Subfloor can and should be fastened to joists regardless.
You can probably use a sparser fastener schedule on the first layer, then go whole-hog on the top layer. That would require adequate penetration into the joists, of course.