Why do some fighter jets have two pilots, while some have only one?
Speaking of fighters in their basic role, there are 2.
Interception and escort.
A single seat fighter would be superior in both scenarios because the space occupied by the second seater, plus the life support systems double the weight which can be put to fuel, countermeasures or weapons, and the extra weight and space will affect handling in air to air combat.
When the role is ground attack, 2 seat versions can be an advantage, such as SAM suppression mission, bombing and other types of strikes.
All of the above applies to modern aircraft.
Previously, say the 1970s and before, 2 seat fighters were sometimes necessary due to the technology available at that time. The F-4 and F-14 for example, the 2nd seater operated the radar because the pilot really couldn't keep his head in the cockpit when engaging multiple enemy contacts or when the fight was close in. Head up displays weren't available so the aircraft systems available to the pilot by necessity was kept limited in order to limit pilot overload.
All fighter aircraft have one pilot, though some have two crew members.
Though not fighter aircraft, I believe that the SR-71 backseat crewmember operated the reconnaissance equipment as the single crewmember on the U2 was often overloaded with keeping the thing in the coffin corner and operating the reconnaissance equipment. Jan and Habu mention in the comments that the SR-71 backseat crew member was also the navigator and operated the ECM equipment. Additional comments mention that the B-1B consists of four crew members: two pilots, an OSO (offensive systems operator), and a DSO (defensive systems operator). The B2 has two crew members, both pilots, and while one is flying the other can rest, navigate, or operate the weapons system. Thanks to Jan, Habu, and Joel for comments and clarifications!
It's primarily a question of pilot workload and military policy at design time.
You'll notice that the primary two-seat fighters and attack planes in the U.S. armed forces (designation F or A) were designed in the late Korean through Vietnam eras, representing the third and early fourth generation of fighter design. This was a critical period of transition from the fighter philosophy of the World Wars and Korea, primarily day fighters engaging in visual-range combat with guns, to modern air combat involving all-weather precision engagements beginning BVR through use of radar, missiles and targeting computers.
As these systems were added to fighter cockpits in the early "century series", developing what would eventually be known as the "multirole fighter", pilot workload grew dramatically compared to the relatively simple layouts and weapons systems of propeller and early jet dogfighters. As a result, these systems, intended to increase pilot situational awareness, ended up doing the exact opposite, forcing the pilot to keep his head "in the cockpit" reading gauges and displays, with his situational awareness of what was going on outside the plane somewhere around his ankles.
With the problem identified but insufficient technology to take critical "heads-down" tasks like navigation away from the pilot, designers initially addressed it by adding a second crewman, whose job it would be to handle tasks not directly associated with the primary operation of the plane, such as navigation, managing the radar, keeping an extra pair of eyes on the sky around them, handling radio communications, etc. This guy is officially known in most situations as the Radar Intercept Officer or RIO, or informally as the GIB (Guy In Back).
It would take a few more technological developments, like the inertial navigation system, heads-up display, HOTAS control layouts, the integrated fire control computer, and advanced C4I capability like AWACS/JSTARS, before the workload inherent in the average fighter sortie could reasonably be handled by one crewman. AWACS can guide and advise pilots much like civilian ATC, the inertial navigation system allows pilots to simply point their plane in the indicated direction as opposed to monitoring nav beacons to figure out exactly where they were, and the HUD and HOTAS got the pilot's head out of the cockpit by placing the information and controls he needs to fly the jet effectively in combat where they're supposed to be; right in front of him and/or at his fingertips.
The primary fighter and attack jets of the third and fourth generation to utilize a 2-man crew include the F-4 Phantom, F-111 Aardvark, A-6 Intruder, the F-14 Tomcat, and the B and D variants of the F-15 Eagle, F-16 Falcon and F-18 Hornet. Notice by the development of the F-15 through F-18 that designers and US top brass were already considering single-seaters to be sufficient; the development and integration of the aforementioned systems into U.S. fourth-generation fighters had successfully made the workload presented by the plane more manageable by one person, thus the backseater (who required expensive flight training just like the pilot) could be moved to a second plane as pilot instead of riding along in the first, and the B/D variants of the Eagle, Falcon and Hornet were primarily used as trainers. However, all these designs were laid out in both one and two-seat variants just in case; the next fighters developed domestically for the USAF, the F-22 and F-23, were single-seat only (at least one two-seat F-22B was built, whether as a trainer or preproduction evaluation model, but the USAF never seriously considered a two-seater). The F-35 was never even proposed as a two-seater, primarily because every cubic inch of the design is spoken for especially in the STOVL-capable B variant.
The remaining two-seat fighters in the U.S. arsenal are the F-15E strike fighter (the backseater having the unique title of "Weapons Systems Officer" or "Wizzo" and being responsible for the fairly complex radar and targeting systems aboard) and variants of the F/A-18 including the F-variant "Super Hornet" and G-variant "Growler" EW fighter. In all these cases the GIB usually manages the advanced radar, targeting and jamming systems of these craft, as well as assisting in dogfighting by providing a second set of eyes especially behind the aircraft. The EA-6B Prowler, an older EW aircraft replaced just this year with the EA-18G Growler, had a crew of four; one pilot and three countermeasures officers.
In addition to Vivian jeet Singh Sudan's answer, most tactical aircraft also have training versions, which are indeed two-seaters with dual flight controls with the instructor sitting in the back.
The two-seat Eurofighters, Rafales, versions B & D of the Eagle and Fighting Falcon, anything from MiG or Sukhoi with a -UB suffix, etc. are all examples of this. That's not to say that they can't be operated in a pilot + weapons officer configuration (or single-pilot for that matter) and they normally retain full combat capability, but they're primarily intended for initial training, checkrides, and the like.
The primary reason any fighter aircraft would be designed for two crew members is work load. As avionics, sensors and weapon systems advance they become easier for a single pilot to operate, which is why far fewer fighter aircraft have two crew members now than in the past.
Two-pilot versions of almost all military planes exist (including the SR-71 until its retirement). They are for training pilots to fly them.
Others have already provided many details on the uses for two-seat fighters, US names and practices, etc. but note that for the Rafale specifically, the two-seat variant is not merely a training version. In fact, some users, including the French Air Force, have more two-seat than single-seat planes.
The person seating in the second seat is often a “navigator” who assists the pilot and operates the weapon systems but I think that their controls are exactly the same so that the plane could be piloted from the back seat. Note that the Rafale was not designed as a fighter but as “multirole” aircraft, doing everything including reconnaissance, ground attack, close-air support, and nuclear strike.
Some missions benefit from a two-man crew while others do not, hence the two variants. On the other hand, the reason why some planes only have one seat is that the single-seat variant has a lower cost, lower weight and extra fuel tanks.
Unless there has been a major change in AF doctrine, a two-seat fighter will ALWAYS be necessary, simply ask this question "When was the last time any ONE person could even be ALONE in a room (remember "NO-LONE ZONES" ) with a nuclear device, let alone having full control of one?" The Air Force I served for 24 years would answer "NEVER!" Even if a "mad" pilot could somehow steal a fighter with a "silver bullet" hanging on it, nothing would ever happen because with no warm body in the back seat to activate the "Nuclear Stores Consent" switch, the nuclear store goes nowhere. The pilot could try and pickle off the bomb, but without toggling that switch in the back, the payload stays onboard. The only AF fighters (that I knew about anyway) having this switch were the F-111, F-4, F-16 (two seat), and F-15E Strike Eagle.
With the technology available today, the ideal number is zero. But traditionally many tactical fighters had a crew of two because it made for more efficient operation in missions with a high workload. The "backseater" would perform tasks like interpretation of radar imagery, navigation and the operation of ECM (Electronic Countermeasures) while the pilot concentrated on flying.