It's hard.
If numpty manager has support of higher ups:
Key advice is to 'rise above' as Michelle Obama would say, pity his ignorance and take every opportunity to expose it and call it out. But do it subtly @PhoneyM suggestions are excellent ones.
"Oh, so you think I should do it x way. Funny in the last 500 times oive done that I did it this way and it worked fine". I think I'll stick with the trend and tested industry standard this time, but thanks for the input".
But mostly, just let them prattle on, head tilted to,one side, then do it the way you were going to do it anyway.
That said make sure you keep notes on any dodgy instructions, misdirections, aggression etc might subject you to, noting your objection and the consequences. Keep this as evidence later on if you need it.
If upper management seem ambivalent / non supportive of him:
Expose his shortfalls (subtly) at every opportunity, especially in meetings "oh let me defer to x to answer that one as I know he has a lot of thoughts about it" . And watch him make a tit of himself.
Delegate upwards every time he has a 'better idea' of how to do something "ok so why don't you do it, I'll observe and you can talk me through step by step'. And get EVERYTHING in writing to cover your arse when it goes wrong. You will then have a string (rope) of evidence with which to crucify him when you escalate.
Third option (if you have the patience and like him enough) is to help him, educate him and cal, out his bullshit in a friendly but forthright manner "oh x that is totally daft and will end up in a shit show. Let's do it my way and you can see what I mean ".
Also spark up conversations asking about which management training they have found to be the best and which books they'd recommend for you to read on the matter 😬 might help him to address some of his shortfalls
Also suggest to HR and him that 360 degree reviews are adopted so that you have the opportunity to give robust , helpful upwards feedback. Even better make the 360 review idea his baby for him to take to HR 😬
Hope this helps.