Lightning striking a metal aircraft
A commercial aircraft [...] is struck several times during its whole service life.
In such a case, the airplane acts like a lightning rod. Its metal structure provides the lowest resistance for the electrical discharge on its way between the clouds and the ground. It is not uncommon that the airplane is thereby struck by a complete series of discharges, mostly between three and five, in exceptional cases up to 25.
Since an airplane in flight has no form of grounding, the lightning first enters the structure and leaves it again a split second later. The principle behind this occurrence is known by most people from physics lessons in school. The airframe acts as a so called "Faraday Cage". Like an automobile body the aluminium structure, when struck by a lightning, passes the electric energy around the interior and keeps the passengers safe.
The crucial technical equipment is thereby also kept safe from the high voltage and the aircraft can, in most cases, proceed normally with its flight. But to play it safe every lightning strike is documented by the cockpit crew and the aircraft is treated with a special inspection routine on its next check.
Source: "Lightning Strikes During Flight", Lufthansa Technik
Lightning striking modern aircraft with composite structures (as noted by this comment)
Composite parts that are in lightning-strike prone areas must have appropriate lightning protection. [...] Composite structures are less conductive than metal, causing higher voltages.
Lightning protection on airplanes may include wire bundle shields, ground straps, composite structure expanded foils, wire mesh, aluminum flame spray coating, embedded metallic wire, metallic picture frames, diverter strips, metallic foil liners, coated glass fabric, and bonded aluminum foil.
Lightning can also damage composite airplane structures if protection finish is not applied, properly designed, or adequate. This damage is often in the form of burnt paint, damaged fiber, and composite layer removal.
Source: "Lightning Strikes: Protection, Inspection, and Repair", Boeing, 2012
New technology improving the lightning protection of modern aircraft
Traditional methods to protect composite aircraft from lightning strike damage rely on a conductive layer embedded on or within the surface of the aircraft composite skin. This method is effective at preventing major direct effect damage and minimizes indirect effects to aircraft systems from lightning strike attachment, but provides no additional benefit for the added parasitic weight from the conductive layer.
A new multi-functional lightning strike protection (LSP) method has been developed to provide aircraft lightning strike protection, damage detection and diagnosis for composite aircraft surfaces. The method incorporates a SansEC sensor array on the aircraft exterior surfaces forming a "Smart skin" surface for aircraft lightning zones certified to withstand strikes up to 100 kiloamperes peak current.
Source: Szatkowski, G. N. at al.: "Open Circuit Resonant (SansEC) Sensor Technology for Lightning Mitigation and Damage Detection and Diagnosis for Composite Aircraft Applications", NASA, 2014
Further information can be found on the internet, see for example "Playing with Lightning in the Name of Aircraft Safety", NASA.
For the science behind the Faraday Cage and lightning striking insulators, please refer to Physics.SE.