You are confusing/conflating two ideas:
- whether a question is grammatically correct in English; and
- whether a question naturally elicits a given answer.
Via links you provided in comments under your question, I found a useful example that highlights this difference:
Indirect question:
(23) a. They have forgotten which problem they should solve by Fourier analysis.
b. * How have they forgotten which problem they should solve?
- Be sure to interpret How in (23b) as modifying the complement verb solve, as indicated by the trace, not the matrix verb forgotten. In other words, a possible answer to (23b) is by Fourier analysis, but not by succumbing to Alzheimer's.
- Wh movement in English
The intended answer there was "Fourier analysis" (item 23a), but the question in item 23b doesn't elicit that answer.
Likewise, your first sample question
Which book did you find with 500 pages?
doesn't elicit the intended answer
I found a book with 500 pages.
Likewise with your second sample question. The "which book" question doesn't match the intended answer of "I found it".
However, just because a question doesn't match an intended answer, it doesn't mean that the question itself is ungrammatical. Both sample questions make sense grammatically.
The question's title asks:
Can “to do something” refer to a noun with wh question?
I take that to ask whether something like "I found it" (cf your "to do something") can refer to a noun like "a book" (cf your "noun") by asking "Which book did you find?" (cf your "with wh question").
The answer is that they are not equivalent: "I found it" isn't a noun - it's a whole statement/assertion/proposition. However, the assertion does refer to a noun ("it"), which is also used in the wh question. The answer to the wh question, however, should be a noun (or noun phrase) that is more specific than that mentioned in the question.
That is, if the question asks "Which book with 500 pages did you find?", the reply "I found a book with 500 pages." isn't a particularly satisfying answer. More acceptable answers include "I found the white book with 500 pages." or "I found the original book with 500 pages." etc. In each case, the answer narrows the universe referenced in the wh question, thereby addressing the operative part of the question, namely, the word "Which".