Why is there typically a large gap between the first flight and mass production of aircraft?
You don't want an aircraft that just 'works'- rather, you want an aircraft that satisfies your needs. The first flight is usually made by a prototype and does just that- it flies and pretty much nothing else. 

Only once you start the flight tests do you understand the airframe limitations and whether the aircraft meets the requirements; usually, a number of modifications are needed. Also, the first flights are rarely, if ever in production configuration. In most of the cases, the required systems are fitted later. In general, most of the combat aircraft bring about substantial improvement over its predecessors- in fact it is a requirement, as the old ones can be used with small improvements at a much lesser cost. 

Me 262 was really a revolutionary product and the use of jet engines caused a number of delays; in fact the prototypes were flight tested with piston engines in 1941. The first test flight happened with piston engine- just as well because both the jets flamed out soon after takeoff. By the time the second and third prototypes, the engines had been changed. However, these engines (Jumo 004) were larger, requiring larger nacelles, which in turn required a bigger vertical stabilizer (the landing gear was changed later). Pre-production of Me 262 had started in 1943 (and went nowhere due to engine troubles) when it was decided to change it into a bomber, further increasing the development period. By the time it took the field, it was in too few numbers to do anything.

Another example is the Mirage III. There were significant differences between the aircraft in first flight and the production one. The prototype never reached the required Mach 2 in level flight.The first one to do was the pre-produciotn Mirage IIIA with an engine with more than 30% extra thrust, lengthened fuselage for radar etc. Even this version was not combat capable- that was the Mirage IIIC.

The design is not frozen till the flight testing is over and the production plans can only be finalized after that- you never know what'll change (for example the hugely successful Su-27 underwent a change in wing design midway through testing). The delays due to setting up of production comes later and is normally quite less for countries/companies having experience. It is the design freeze that takes up more time during test flights.