The particular shot you are asking about was done with models. Although Top Gun had the full cooperation of the U.S. Navy, and many of the shots you see in the movie were authentic, they wouldn't allow a stunt that dangerous for the purposes of a film. Any stunt that required damage, destruction, or a near crash of a plane was done using a variety of models and filmed by a dedicated special effects team. Check
Check out the following YouTube video for more detailed information--the flat spin is shown at about 11:30. TheThe large (~10' long) model F-14 is hoisted up by a crane, set spinning on its mount, and then released. Cameras on the ground catch it all, then editing and context and music and sound do the rest.
The full video is about 17 minutes long and extremely interesting!