僕は山崎先生が昨日何を言ったか忘れてしまった
I don't understand what is that か doing in this sentence I mean, It should be an を but there's already one but anyways I don't think this is related to the problem
The way to break this sentence down is like this:
僕は [山崎先生が昨日何を言ったか] 忘れてしまった。 I forgot [what Yamazaki-sensei said yesterday].
The か marks the clause as an embedded question that the main verb bears on, and this sentence is great example of the standard pattern. You usually don't need を after an embedded question. Instead, you simply raise a question using an informal sentence structure (no polite です・ます) and then comment on it.
Hope that helps!