If a diplomat were to request access to the flight deck with proper identification, would he/she be allowed to visit the cockpit of a commercial airliner during flight?
Generally, airlines are required to have content in their ops manual clearly stating who is entitled to flight deck access from the point the engines are started until shutdown. In some countries, such as the UK, airlines are required to limit access only to essential personnel, and foreign airlines must follow the rule while in UK airspace. I would find it rather disturbing that an airline would allow access to the flight deck during flight ops to someone just because they have a diplomatic passport, given that some countries play it fast and loose with such documentation, and flight crews are not equipped to validate a passport.
SKYbrary is a wiki created by the European Organisation for the Safety of Air Navigation, International Civil Aviation Organization, and the Flight Safety Foundation to create a comprehensive source of aviation safety information freely available online. Its guidance on this subject is crystal clear:
In the air, procedures vary from airline to airline and from region to region, but the principle that only those with legitimate need must be permitted flight deck access must be paramount. Beyond the pilots at the controls, this will include relief, check and training pilots. Exceptionally, such flight deck occupancy may exceptionally be extended to include other specifically-authorised employees of the operator - pilots, cabin crew and maintenance personnel. Flight Operations Inspectors carrying out observations on behalf of the State Regulatory Body may also be permitted access at the discretion of the aircraft commander subject to valid identification being presented prior to entry approval.