The answer to how Israel won the Six Day War has filled numerous books and cannot be done justice in a short-form resource like this. At best, one can only give a summary in this space, but even the summaries that came before mine have given short-shrift to some key factors.
Obviously, air superiority ranks first. The Israeli Air Force's success at catching the Egyptian and Syrian air forces on the ground paved the way for full IDF control of the skies thereafter. That success came partly through planning and largely through Egypt's failure to have hardened hangers for its aircraft, adequate air defense capabilities, or better communications and control systems. Moreover, their reliance on Soviet military doctrine left very little initiative with local commanders, meaning that a shutdown of communications would keep Arab forces with their heads down. It has been rumored that Israel effectively intercepted Arab communications and made its own broadcasts pretending to be Arab leaders, giving out false and misleading orders.
Critical intelligence that came from human intelligence networks, such as Eli Cohen, and more conventional electronic intelligence (i.e. monitoring various aspects of enemy communications whether or not codes had been broken) were even more valuable to Israel. Cohen, among other things, was said to have posed as a trusted advisor to a Syrian general and made the comment that cedar trees should be planted by Syrian positions on the Golan Heights so as to provide shade to the soldiers there. The trees also provided perfect positioning points for Israeli artillery. According to Isser Harel's book, Israel also used humint from Cohen to find out what Arab soldiers were fed by their own armies; Israel made sure that it would feed POWs better and more food than they received in their own camps with the idea that the Arab fighters would feel demoralized with the knowledge that Israel had more food to feed prisoners than their own armies had to feed their soldiers.
Jordan's lateness in joining the battle allowed Israel to focus on its enemies north and south first, and after taking Sinai and the Golan Heights, Israel could focus on the West Bank without worry about its flanks. Much credit for that must be given to Egypt's Nasser who incorrectly boasted to Jordan's king that Egypt had destroyed much of the IDF's air power.
Nasser's ineptitude cannot be limited to that one incident. Prior to the war, Nasser changed his mind four times on his country's invasion strategy and goals, forcing large troop movements multiple times, thereby creating a sense of chaos among the troops, and sucking on factors such as morale and readiness.