Any "rules" found codified somewhere are bunk if they aren't logical, and printers' efforts to impose bad rules should be resisted.

As much as possible, punctuation should be attached to where it logically goes.

As a simplification, you can omit a full stop next to another punctuation mark.

If the quoted chunk is Why is that spider there? then its question mark belongs to it and should be inside its quotation marks.

If the quoting chunk is When did Mary ask (that)? then it too has a question mark, and if (that) is replaced by actual quoted words, its question mark should keep its relative position. Thus:

(a) When did Mary ask "Why is that spider there?"?

The same principle should apply regardless of the punctuation mark, so logically:

(b) When did Mary say "Look at that spider there."?

(c) It was Mary who asked "Why is that spider there?".

It is an allowable simplification to omit the full stop in (b) and (c), but I should regard this as optional, and depending on the bloody-mindedness of my mood I could well insist on keeping them.

Another concession to common printers' usage is the illogical and unnecessary comma introducing quoted matter:

(d) It was Mary who asked, "Why is that spider there?".

I don't like this at all, but in some of my writing, in moments of cravenness (or unusual contentedness) I defer to the convention because it's easier not to think about how to do it correctly.