貴様、何をにやついておるのだ…?
What are you grinning at, you bastard?
This sentence (asked in this question) seemed fairly natural and simple to me...until I realized にやつく is an intransitive verb. [×]彼は私をにやついた is ungrammatical. Instead, you have to say something like 彼は私を見てにやついた.
Then why is the first sentence ever possible? Well, after some pondering I came up with a similar expression:
何をぐっすり寝ているの、早く起きなさい!
So apparently these 何を with intransitive verbs mean why rather than what. But is that really true? I found a page where one person says 何を can mark a reason/trigger. But I'm not totally convinced, since all I could find was this short comment. I'd appreciate if someone explain this or point me to a longer article/reference. Should this be considered as a fixed expression like English "how come"?
(Just to be sure, as a native speaker of Japanese, I know these examples using 何を are natural, but I'm just having trouble getting a nice grammatical explanation.)