About 2/3 of US astronauts were military and among most are from the Air Force, Navy or Marines because that are the US branches that have jet pilots. The US army just has helicopters and no jets, but helicopter pilots from the army or the coast guard have become astronauts too.
There is no need for an astronaut to have a pilot license, but it certainly is a plus if somebody already trained you to be part of a professional crew of a flying vehicle.
A significant number of American commercial pilots are ex military for the same reason.
It also helps that for a lot of the NASA astronaut program a significant percentage of the able bodied males in the right age range had some military experience due some war or another.
That being said about a 100 or so civilians with no prior military service have been NASA astronauts too.
Latest Answers