For USNA, the first step in Commandant selection is identifying a senior O-6 who is a USNA grad and who is on track to make Admiral / General (USMC) -- these are the true superstars. For this reason, is very, very rare for a Commandant who successfully completes his/her tour not to make flag rank. Another factor is the warfare specialty -- first, (to date), they must be in Unrestricted Line (i.e., no Supply Corps). There is an unwritten rule that the Superintendent and Commandant will not be in the same warfare specialty (i.e., aviation), so if the current Supe is an aviator (as is the case today, an aviator won't be chosen as Dant). Next factor is rotation. While a candidate could rotate a bit early or late from his/her current billet, they're typically not going to take someone who just started a job elsewhere or hold someone in a current billet significantly beyond rotation date. Usually, Commandants come directly from a fleet (sea) billet so they bring current operational experience, so a superstar in a shore billet may be at a disadvantage.
I believe for USNA purposes that a list of candidates is provided to the Superintendent who interviews them. The Supe has significant input into the final selection.
Also, as mentioned above, the Supe is not selected by the President. As with all flag officers, the President officially/formally nominates the Supe, who must be confirmed by Congress. I'm not sure exactly how the process works, though the CNO is likely heavily involved. Some of the same elements that apply to Dants also apply to Supes. Some of the differences . . . the Supe by law must retire at the end of his/her tour. Thus, they have to think about choosing someone who is (most likely) not on track for a 4th star. This is not a question of ability -- part of how far you can go relates to the jobs you've had, who've you've worked for and where they are now, your political connections, etc.
From what I've heard, given all the requirements, there is typically a fairly small pool of available 2- and 3-star officers from whom to choose. There has been a move afoot in recent years to select a USMC officer as Supe. However, the pool of USNA grads at the 2- and 3-star level in the USMC is very small. In any event, it's yet to happen (though there have been USMC Commandants).