In today's ask Oscar The Pilot, we will answer: What happens during pilot incapacitation? What happens if a pilot dies during a flight? Do Pilots train on what to do and how often does it happen?
What happens if a pilot dies during a flight?
There is a particular term for this scenario in Aviation called: "Pilot Incapacitation".
When compared with other routinely trained non-normal conditions, pilot incapacitations occur frequently. It occurs in different forms, in all age groups and all phases of flight.
What's the definition of Pilot Incapacitation?
The ICAO Manual of Civil Aviation Medicine defines it as "Any reduction in medical fitness to a degree or of a nature that is likely to jeopardize flight safety". 
What are the causes of Pilot Incapacitation:
There are two types of incapacitation:
1. Obvious Incapacitation:
Total loss of capabilities, easily detectable.
2. Subtle Incapacitation:
The most dangerous as it's difficult to detect, and they occur most frequently. The issue is that the affected pilot may look well and continue to operate but at a less than optimum level of performance.  In a simulator study, it was found that the meantime to detect subtle incapacitation was 1.5 minutes. 
Incapacitation effects can range from loss of function to unconsciousness or death.
There are plenty of causes, some use medical categories to classify the causes, and others use plain, direct reasons; I chose the latter as I'm not a medical specialist. After scouting through several documents - Check references -, I can now list the following reasons:
- Uncontrollable bowel action and other gastrointestinal symptoms
- Earache/blocked ear
- Faintness/general weakness
- Headache, including migraine
- Vertigo/disorientation 
- Heart Attack
- Laser Strike
- Partial Paralysis
- Loss of consciousness
- Fatigue  
How to Identify Pilot Incapacitation:
The 737 Flight Crew Training Manual states: "The key to early recognition of pilot incapacitation is the regular use of crew resource management concepts during flight deck operation. Proper crew coordination involves checks and crosschecks using verbal communications". 
- Both Pilots should be monitoring each other for any incapacitation symptoms throughout the whole flight.
- The "80" knots crosscheck at Takeoff can be used to identify incapacitation on top of a speed check.
Symptoms - Warning Signs:
- The pilot's inability to respond appropriately to two verbal communications.
- Incoherent speech
- Strange behaviour
- Irregular breathing
- Pale fixed facial expression
- Jerky motions that are either delayed or too rapid
- Comment on heartburn 
What to do In case of Pilot Incapacitation:
If any of the symptoms are present in the other pilot, immediately take control of the aircraft and fly to a safe destination. Follow the axiom: "Aviate, navigate, communicate".
Actions to be taken:
- Ensure the aircraft is under control & engage the autopilot to reduce the workload.
- Declare an emergency with a Mayday.
- Call the cabin crew to the cockpit; they are trained to restrain the incapacitated pilot by sliding the seat back and securing the pilot using the shoulder harness.
- Prepare the aircraft for landing as early as possible, and keep in mind there will be an increased workload.
- Don't allow the incapacitated pilot to perform any duties. If you need help with the checklist, ask the cabin crew to read it out.  
Records Of Pilot Incapacitation:
I tried looking up data statistics on airline pilot incapacitation frequency but couldn't find a source stating all the declared incapacitations worldwide. Nevertheless, I found few papers on the matter; as in any research paper, the data would be limited to a time range & a particular region. Few extracted information should suffice to give us a knowledge bite that's suitable for this type of article & blog.
Note: Find all the references below.
- An examination of in-flight deaths of airline pilots between 1961 and 1968 found 17 reported cases, all resulting from heart disease. Five of the 17 cases ended in aircraft accidents, four of which were fatal, resulting in 148 fatalities. Another five cases nearly resulted in accidents.
- A review of IATA data found 208 in-flight medical incapacitations between 1965 and 1977.
- Ten cases of sudden in-flight incapacitation out of a population of 1,800 Air France pilots and flight engineers from 1968 to 1988.
- 39 incapacitations and 11 impairments of U.S. airline pilots on 47 flights during the period 1993 to 1998
- 27% of approximately 5000 respondents (Airline Pilots) reported about 2000 incidents of significant in-flight incapacitation in a questionnaire administered to pilots of IFALPA-member associations in 1967. 
- In 2004 there were 16,145 UK/JAR professional pilot license holders. Of the notified medical events, 36 presented as incapacitation. 
Do Pilots train for Pilot Incapacitation:
Yes. They Do!
- Every year, each simulator includes pilot incapacitation, whether on Takeoff, which would require either an aborted takeoff or continuing the Takeoff on your own, depending on the speed regime.
- We even simulate one engine takeoff and landing with one pilot incapacitated.
What would happen if the captain got incapacitated and the first officer was under training?
The question is basically asking what a trainee pilot would do if the instructor were incapacitated?
Two Scenarios here:
- The first officer under training still hasn't released his safety pilot.
- The First Officer under training released his safety pilot.
1. The first officer under training still hasn't released his safety pilot:
This would mean that three pilots are flying in the cockpit. If the instructor got incapacitated, the most senior pilot would take control of the aeroplane. In this case, it would be the safety pilot (Third Pilot), who's the more experienced, who would take control of the aircraft, and the trainee pilot would be there to help. That's the most crucial reason that a safety pilot is there in the first place.
2. The First Officer under training released his safety pilot:
Releasing the safety pilot would mean that you passed captain incapacitation training, so in this case, the trainee first officer assumes control of the aeroplane and land.
You might like this other article: The Complete Guide To Becoming A Pilot (5): Type Rating & Beyond
In the end, I hope that this was a sufficient answer to this question, and I'd like to advise my fellow pilots to take care of their health and the food they eat. For all the passengers reading this; nothing to worry about; pilots are trained for crew incapacitation, and it's an event that doesn't happen too frequently; even if it did, it would not automatically lead to a fatal accident. There were 54,295,899 flights and 217 accidents involving U.S. Part 121 scheduled and non-scheduled airlines between 1993 and 1998. 
 ICAO. (2012). Manual of Civil Aviation Medicine (3rd ed.).
 Dejohn, Charles & Wolbrink, Alex & Larcher, Julie. (2006). In-Flight Medical Incapacitation and Impairment of U.S. Airline Pilots: 1993 to 1998. Retrieved from https://www.researchgate.net/publication/6753836_In-flight_medical_incapacitation_and_impairment_of_airline_pilots
 Pilot incapacitation. SKYbrary Aviation Safety. (2021, October 26). Retrieved from https://skybrary.aero/articles/pilot-incapacitation
 Australian Transport Safety Bureau. (n.d.). Pilot incapacitation occurrences 2010–2014. Retrieved from https://www.atsb.gov.au/media/5768970/ar-2015-096-final.pdf
 The Boeing Company. (2005). Flight Crew Operations Manual.
 In-flight pilot incapacitation (OGHFA SE). SKYbrary Aviation Safety. (2021, November 9). Retrieved from https://skybrary.aero/articles/flight-pilot-incapacitation-oghfa-se
 Thomson Airways. (n.d.). 737 Quick Reference Handbook. Retrieved from https://www.737ng.co.uk/737-800%20Quick%20Reference%20Handbook%20(QRH).pdf
 The Boeing Company. (2007). Flight Crew Training Manual.
 Evans, Sally & Radcliffe, Sally-Ann. (2012). The Annual Incapacitation Rate of Commercial Pilots. Aviation, space, and environmental medicine. 2012;83:42-49 83. 42-9. 10.3357/ASEM.3134.2012. Retrieved from https://www.researchgate.net/publication/221772960_The_Annual_Incapacitation_Rate_of_Commercial_Pilots