Pakistan is deep in political malaise and weariness right now. Elected leaders keep being shown as both corrupt and incompetent, and as such everyone hates them.
Khan's a firebrand, a populist. Despite being involved in politics for over 20 years now, he can claim to be an "outsider"...to an extent. A lot of the people around him are known for being on the take, and he himself has embraced a fairly hardline and conservative interpretation of Islam. So he's not tainted in the same way the usual names are, but his views are more or less dependable and in-line with the kind of country the military wants to run.
The military likely see him as a way of defusing some of the political apathy in the country right now while still being dependable and controllable. They'll let him play out his (inevitably limited) anti-corruption crusade at home, while they continue to call the shots on India, Kashmir and Afghanistan.