Did they really throw an F-14 into a flat spin and then have to recover it? Or is that a model shot? It seems (to a complete layperson) like an unthinkably-dangerous thing to do, but the shot looks just as authentic as all of the other real F-14 flight scenes.
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 out the following YouTube video for more detailed information--the flat spin is shown at about 11:30. The 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!