Is there a reason a pilot would takeoff downwind or land downwind? Is it legal to do this?
It's perfectly legal, but check the Chart Supplement (or AFD, or instrument approaches) to see if there are special exceptions for that airport.
If it is a non-towered airport and you aren't assigned a runway, you should of course try to use the prevailing runway that is already in use by other traffic in the pattern when it makes sense.
Some airports have obstructions in one direction of their runways that make it necessary (or safer) to always land or depart in a certain direction.
Some runways have a steep incline in one direction, making it preferable to land upslope and depart downslope. (For example Lukla, Nepal: YouTube)
It's also common for larger airports to have preferred directions for arrival or departures in order to keep the flight volume high, even when the wind prefers other runways.
However, that usually relates to operating with intentional crosswinds at an airport that has parallel runways in a primary direction (allowing them to conduct more simultaneous flight operations), but not in the intersecting direction.
Yes, aircraft do take-off and land downwind sometimes. During low wind conditions it is sometimes preferable to use a runway in the downwind direction for noise abatement reasons.
During downwind landing the ground speed will be higher and therefore it takes more distance to stop the aircraft. This increases the risk of a runway excursion.
During downwind departure a higher ground speed is needed to take-off and therefore a longer runway will be required. An other effect is that the climb-out angle is lower due to tailwind, lowering the obstacle clearance and increasing the risk of Controlled Flight Into Terrain (CFIT).
Commercial aircraft have limits one the amount of tailwind that is allowed on take-off and landing. For most aircraft it is 10 or 15 knots.
For more information about the safety aspects of tailwind operations see this report by NLR.
Landing downwind is often the only option when flying an instrument approach procedure to minimums (the lowest ceiling at which landing is permitted).
Many airports only have approaches to one runway direction. In the event that the approach is required and circling is not possible, a straight-in downwind landing is the pilot's only option.
For example, given an approach to runway 27 with winds of 8 knots at 080:
Circling MDA | 1100 feet MSL Straight-in DA | 700 feet MSL Field elevation | 450 feet MSL
If the clouds are below 1100 feet, a pilot would be unable to circle to the "correct" runway 09; they would have to land straight in to 27, which is a downwind landing.
Given the aircraft I personally fly, I will avoid doing so and divert to an alternate if the tailwind is higher than 10 knots or the runway is shorter than 4500 feet. Tailwind landings are inherently riskier and I'd rather take the delay.
Floatplane operators may occasionally choose to takeoff with a light tailwind when to do otherwise would mean bucking a strong river current. I live on Oregon's McKenzie River, and doing this when operating out of Leaburg Lake (actually just a wide spot in the river) many years ago in a J3 on floats with only 85 horsepower made such takeoffs easier.
In the case of motorless flight (preferrably intentionally, i.e. with a glider) the choice of landing direction for an outlanding is very strongly influenced by the terrain. Of course it is much preferrable to land with headwind, but in uneven terrain this can be impossible. In sloping terrain, it can be better (or compulsory) to land into direction of the steepest rise.
The same thing also can be the case for landing or (reversed) for takeoff on airports with very pronounced runway slopes (mostly in mountaineous terrain, e.g. in Courchevel), or glacier landings.
In some cases, it is simply convenient to land downwind, again esp. for motorless aircraft to reduce the distance to the hangar - conditions permitting, of course.
I fly small Cessna aircraft, but frequently fly out of airports with 10,000 ft. runways. (A C-172 typically needs around 1,500 ft).
So when its more convenient for me, I can ask the Tower for an "Opposite Direction Departure", meaning that I want to take off with the wind.
It does take me a little more time to get my airspeed up and take off, but so long as I have plenty of runway in front of me, its not a problem. And it generally means I can take off more directly towards my course, instead of taking off, flying a pattern around the airport, then getting on course.
Sometimes the sun is setting directly over the end of the runway with the headwind. Definitely a challenge, and it is a wise decision to land in the other direction unless the tailwind isn't too strong. If it's a controlled airport, you have to get a clearance for that of course.
When I flew light airplanes in Alaska there were a few one-way-in-one-way-out strips that I would take the tailwind before departing. Very common in some parts of the world.
A good answer would be, "Yes, when operational constraints dictate." A pilot needs to consider the risks when deviating from standard operating procedures and practices. There are reasons airplanes take off into the wind, and they are the same reasons birds takeoff into the wind. Consider that birds have been flying a very long time. As far as I am aware it is not illegal to takeoff downwind within the stipulations of the regulations as noted elsewhere. On landing one can declare an emergency if necessary.
I had over 300 landings on the USS Nimitz and only one was downwind. At home, ashore, I remember only a few hairy crosswind approaches, but no significant downwind approaches.
The carrier often augmented, or made its own wind over the deck. The approach speeds of fighter jets are pretty high. The A7-E came in at around 120 to 140 knots, if my memory serves me correctly. The headwind made approaches safer.
During flight operations in the Mediterranean 2 of my comrades had a midair collision. One ejected into the Mediterranean, and the other diverted to an airbase on Crete. Operational considerations saw the boat turned downwind towards the pilot bobbing up and down in the 60 degree water, and this set up an unusual relative wind over the deck. There were both strong downwind and crosswind components.
A pilot without much shipboard experience came in for the break and by the 45 degree position found himself low and well right of center line. The pilot had been too close abeam for the relative wind, and failed to correct during the remainder of the approach. The LSO ended his approach with the call "Wave off, wave off!" At this point his altitude was below the top of the Island. He went to full power and wrapped the aircraft up into a 45 degree turn to wave off over the deck. Waving off below and to the right of the Island would have been unusual, but it also would have been safe.
I was watching the approach on the platform cameras in the ready room. I thought to myself that this was the textbook scenario for an approach turn stall. Right after that thought his nose sliced down out of the turn. It was quite dramatic. During training at altitude it is difficult to get a good sense of the quickness of the stall. The A7 impacted the water just behind the ship. Parts of the plane and water rained down on the flight deck. He did not eject.
Think through the departure or approach, and adjust procedures to stay safe. If you will be deviating from standard operating procedures and practices, brief that part of the flight. If the decision has to be made airborne: "aviate, navigate, and communicate."
Commercial passenger operations flying under Part 121 will have an FAA approved OpSpec (Operating Specifications) that will specify the maximum tail wind component for landing. If the wind is above that, the pilot must land the other way or find a different runway, or risk disciplinary action by his company.