Do you know what he is pretending that the broom is?
The that-clause within the what-clause is confusing me. Is this a grammatical sentence?
It is indeed a grammatical sentence. It is confusing because it includes three separate clauses, with the second ‘embedded’ in the first and the third embedded in the second:
Two syntactical devices are employed to put these three clauses into the proper relationship in a single sentence. We work from the ‘bottom’ up, because each lower clause has to be restructured to fit into the next higher clause.
Now you replace the X in Clause 1 with the transformed Clause 2, and you have your original sentence:
† In traditional grammar this is called a subordinating conjunction, and Clause 3 is said to be cast as a subordinate clause.
‡ Free relative clauses are discussed at many places on ELL; click free-relative-clauses for a list of related questions.