There is some overlap of this concept with the concept already discussed elsewhere on this site (http://english.stackexchange.com/questions/43237/phrase-for-focusing-on-unimportant-details) of focusing on details instead of going to the heart of the matter (e.g., “re-arranging the deck chairs on the Titanic” –or, even better, “straining out a gnat while swallowing a camel”, or – the list seems endless – “penny wise and pound foolish”…). Such behavior is self-defeating, but is a (proper) subset of the set you are asking about.
So, to cut to the chase: There is a graduation of such aphorisms/situations.
“going in circles” is the least ominous. (e.g., Pooh circling the handful of trees, tracking his own tracks, thinking he is tracking a woozel…)
“spitting into the wind” is the next step up in ominousness. (e.g., being annoying by trying to show how friendly you are)
“sawing off the branch you’re sitting on” (as noted by gasan, (and corrected by me)) is the next step up. (e.g., unions making demands that bankrupt the company that employs the workers)
being “hoist” by your own petard” (as noted by MT_Head) is the most extreme. (e.g., operation Barbarossa)
And don’t forget the classic, “If you think you’re outclassed, you are.”
And don’t forget the adage, “Argue for your limitations, and they are yours.”
And the adage, “A dog that scares many rabbits kills none.”
And we all know the story of the nurse who wakes you up to give you your sleeping pill.
And finally, if you simply want a generic expression that focuses on the stupidity/ineptness of the actor, “snatching defeat from the jaws of victory” serves nicely.