For example how widespread was this problem from medieval to, say, Napoleonic times?
Is the idea largely a myth? I can imagine that the truth of the matter is that the aristocracy did indeed take up most of the powerful ranks in a European army, but that they were far from useless due to being the only part of the population with any sort of education.
Okay, so to preface this, my expertise falls a little after the period you specified- However, I hope it answers at least some of your question.
In the British Army, at least, the aristocracy proper constituted only a small proportion of the officer class. Only 13% of the Army's colonels in 1854 came from aristocratic backgrounds. In 1847, a little over 1% of infantry officers were titled. While aristocrats tended to gravitate towards more fashionable regiments such as the Guards and some of the cavalry (famously, the 11th Hussars under their martinet Lord Cardigan were renowned for being a staunchly elitist regiment), even there they constituted a minority.
A military career required all but required a private income- An income of at least 50 pounds per annum was required in the decades prior to the Crimean War. His expenses, which covered things like the mess bill, uniform costs, and even the fund for the regimental band, sometimes ran in excess of his pay. In the latter half of the 19th century, the situation did not improve considerably.
Prior to the abolition of the sale of commissions, wealth, rather than birth, determined who could enter the officer class. While contemporaries stressed that an officer must, first and foremost, be a gentleman, this category was defined by education, manners, or habits rather than being born into it. The shared identity as 'gentleman' rather than 'gentry' or 'peers' gave the officer class its remarkable espirit de corps.
Sources:
Raugh, Harold E. The Victorians at War, 1815-1914
Spiers, Edward M. The Army and Society, 1815-1914 and The Late Victorian Army: 1868-1902
Strachan, Hew. Wellington's Legacy: The Reform of the British Army, 1830-54
I asked a related question a few months back about how the system of selling commissions worked, and got a good answer. Here's the link
Well, I'm not an expert (at all) on the medieval era, but I think from the Roman empire onward (and possibly before that), the aristocratic classes of society were the only ones educated in martial tactics and strategy, while the enlisted soldiers and possibly some lower field officers were drawn from lower and middle classes.
I think the most prominent example of your question, though, as far as incompetence of western military leaders, and where this historical meme comes primarily from, is the Battle of Balaclava in the Crimean War, and more particularly, the infamous "charge of the Light Brigade" (sorry for sending you to the wiki page, but it has quite a bit of good information and further reading listed), where petty rivalries between Lords Lucan and Raglan, along with over-enthusiasm for the effectiveness of cavalry by Captain Nolan, resulted in an unnecessary, ineffective, and disastrous charge down a valley surrounded by Russian artillery on three sides, where 110 troopers were killed and 161 wounded. The French officers on the field were pretty appalled by this, one commented "It was magnificent, but it is not war." (it would be a French Marshal who would ultimately take command to win the Crimean War), and it led to reforms of the British military's sale of commissions system. Feel free to correct me if I'm mistaken, but this is probably the most notable instance of aristocratic officers' incompetence leading to infamous disaster and reform, and probably where the general idea comes from of bumbling aristocratic commanders.
EDIT: Up until this time, as far as I'm aware, the sale of commissions still resulted in many prominent regiments being commanded by landed gentry. The top poster here makes a reasonably solid point about wealth, rather than birth, being the primary means to a high commission. I do not disagree with that statement. However, the notion that aristocratic officers were incompetent, in the popular imagination, stems almost certainly from this incident. The recent advent of the telegraph delivering news in near-real time (similar to the televised news from the Vietnam War era), as well as Alfred, Lord Tennyson's poem immortalizing the fatal charge, resulted in the extensive reform of the sale of commissions system in Britain. Prior to this time, though isolated incidents of ineptitude did exist, the public generally did not associate aristocratic officers with incompetence.