From what we now know of Stalin, he seemed to believe in the basics of Marxist-Leninism. As a communist, didn't he fear that killing his own military's leadership would seriously endanger the world's only socialist experiment against capitalist rivals? 1936 moreover was several years after the rise of Hitler. Didn't Stalin realize an escalation of political tensions was going to lead to war soon? There is every indication that Stalin was a ruthless, cruel man. He also displayed moments of great opportunism and caution during his rise to political power throughout the 1930s and his later conduct of the war after 1942. What motivation beyond paranoia led to the purges, which seems like such a self-evident detrimental policy?
It is worth noting that in 1917, in the midst of The Great War (as it was then commonly known) both the French and Russian armies mutinied. That the French mutiny ultimately amounted to little was in no small measure due to both a massive assault by British forces (the Battle of Passchendaele) that occupied German forces on the Western Front, and a declaration of War by the U.S.
However the Russian Amy mutiny led ultimately to the formation of the communist government in Russia that Stalin led. With a repeat conflict against Germany on the horizon in 1936, it is likely that Stalin wanted to so terrorize and cow the officers of the army that none daring enough to organize any such mutiny again would be left . Despite the fact that the Soviet army in 1941 and 1942 was much less successful against the Germans than the Russian Army had been in 1914-1916, no threat of such a mutiny ever materialized during the Second World War.
It is impossible to tell for sure what was inside Stalin's brain. Historians can only speculate on this. I can outline some principal opinions stated in the process of this speculation:
a) Stalin's primary goal was to consolidate his absolute power. Not only to remove any real, or potential or imaginary opposition, but to make sure that everyone was scared to death, and would blindly obey his orders whatever happened. Essentially he achieved this goal; and he won the war, after all. (Whether he won it by a narrow margin or not, is a subject of another speculation).
b) It is not only clear that he knew about the approaching war, but he planned for it, and wanted it. This can be confirmed by his recorded statements, the whole scale of preparations and by his support of Hitler on various stages of his career.
c) It is equally open to speculation whether any of those who were repressed were indeed traitors, or whether they were well-qualified to win the approaching war. In any case, the scale of the purges is well-known, it is clear that most of those prosecuted were neither traitors, nor inferior officers in comparison with those who took their place.
d) That he was simply a paranoic.
But there is really no way to tell for sure what was in his mind.
Stalin developed Lenin's idea of absolute value of the power to the upper limit. Never was he interested in effectiveness for the sake of Russia or even "The Revolution". His only aim was his own power. He had annihilated the lead economists of the USSR, set by Lenin, because they were not his people. He annihilated millions of farmers because his way to annihilate his political competitors needed it.
The army officers were the last people in the USSR who had their own authority independent on Stalin. (Personally they were dependent on him, but their fame already existed and couldn't be cancelled without destroying these officers). Stalin had to bring EXCUSES to the Tukhachevsky pair for years before, agreeing with his views. These people had to die, when it became possible!
Almost all high officers were killed. On the territorial army groups level, for example, EVERY commander was killed.
So, all talk about somebody's treason, or ineffectiveness were pure nonsense. ALL the generals couldn't have been spies. If they were fools, changing them for the arbitrary lower officers doesn't give cleverer men. And talk about Darwin methods is absurd, too. For example, the general, that almost lost the Finnish war, Mesherjakov, got the upper position after the war, and his opponents, on the contrary, went down.
The normal, qualified officers were a constant and real danger to his personal power. For example, if they were left on their positions, then on the start of WWII in USSR, after the terrible losts of the start of the war, they would SURELY change Stalin for another leader. So, he had his reasons.
You need to read the BEST book on the Great Purges, including the purge of the army, written by Robert Conquest, called The Great Terror, a reassessment.
Essentially, Stalin killed off all political socialist rivals within the Communist party and millions of others, including all of the old respected communist guard from the revolution itself, so he could have absolute power. It made NO economic or military sense, but it made political sense so far as it made him absolute dictator.
He did this to his own party through false trials and executions entirely based on tortured confessions. This spread down through the party ranks until the entire communist party was terrorized. Millions were murdered during his purges. He attacked anyone with a power base outside of his control, first, within the country (the attacks on the kulaks and the forced starvation of the Ukraine, then within the communist party itself, then his attack on the army, again, killing tens of thousands of officers. He finished it off by murdering the Secret Police (the NKVD) themselves by the tens of thousands at the end, to kill off witnesses. Often he killed off the best brains, even people in the Census Bureau were murdered for producing populations numbers that were too low! (due to his killings)
You should also read Anne Applebaum's fine book, Gulag: A History.
Stalin, or any other Soviet leaders, did not "
IMO the only two major reasons for the massive purges 1936-38, from Stalin's viewpoint, were consolidation of absolute power and producing slave population for massive Gulag project. You can kind of measure which of the reason was dominating by looking at the percentage of prisoners executed versus sentenced to hard labor camps.
In case of military purges I think consolidation of power was the primary reason. One can find quite a few documents where Stalin amends massive arrest orders to increase the percentage of prisoners to be executed versus sent to labor camps. Here's one in Stalin's own handwriting where he approves execution of 46 generals on a single page.