Can it be said as follows:
He just didn't understand or pretended not to.
in the meaning the he either didn't understand or pretended he didn't?
Your sentence is valid and natural. However, notice that just here may mean two things:
Whatever ironic sense you might have wished to imbue the sentence with isn't really there. You might want to look into omitting "just" for clarity, or rephrasing the first part to "It's just that he didn't understand or pretended not to" as Mr.TRomano suggested.
Yes, there is nothing wrong with that sentence.