The sentence:
"Después de pensar largo rato el aprendiz, al fin preguntó al maestro, si era verdad lo que había oído decir."
is defective from the point of view of punctuation. This would be better:
- Después de pensar largo rato, el aprendiz finalmente preguntó al maestro si era verdad lo que había oído decir.
"Lo que" can be the subject or the object of the subordinate sentence. In this sentence, "lo que" is the subject:
- El maestro no sabía lo que había ocurrido. (The teacher did not know what had happened.)
For "lo que" to work as the object, the subordinate must contain a transitive verb, and "decir" is transitive. In the sentence in question, the subject of "decir" (this is what might be confusing OP) is tacit:
- The apprentice asked the teacher if what he had heard somebody/people say was true.
With an intransitive verb in the subordinate, "lo que" can only work if it refers to the quantity or intensity of the action, for example:
- Después de pensar largo rato, el aprendiz finalmente preguntó al maestro si era verdad lo que había oído llover, o si era solo una ilusión. (This "lo que" means "how much", not "what".)