Can civilian aircraft fly through or land in restricted airspace in an emergency?
FAR 91.3 states that any pilot in command may deviate from any regulation or rules to the extent needed to deal with the emergency.  That includes entering restricted or prohibited airspace.

In the example that you suggested, yes you could do so and land at the Groom Lake flight test facility at KXTA, provided you could reach their controllers or contact Nellis Approach Control declaring an emergency.  I will say that if you do enter R-4808 N and land there, don't expect them to roll out the welcome mat.  You will be immediately met by USAF Military Police who will arrest you, most likely at gunpoint, and spend several hours, if not days, there or outside the compound being extensively questioned by Air Force Security personnel, the FBI and Homeland Security.  Your aircraft will be impounded and inspected, possible indefinitely, and search warrants issued for your property.  If they find out that you faked an emergency to enter that compound, you are in very serious trouble and face a variety of federal charges including trespass upon a classified installation and whatever else the DoJ can throw at you.

In addition, you would need a very, very good reason to even be anywhere near Area 51, as it is in the middle of a military reservation geographically the size of the nation of Switzerland in the middle of south central Nevada.  There are no published routes over the airspace and all commercial and civilian traffic is kept far, far away.  Details about the airfield are not published on government aeronautical charts or regional A/FDs.  See the VFR sectionals and enroute charts below.





While Area 51 is a pretty extreme example, people have had emergencies and landed in military or other restricted facilities.  The usual response from the authorities is to detain and question you to determine what happened and inspect the aircraft to verify your story.  If it's a legitimate emergency, no harm is done and they will release you and the aircraft; the NTSB will file and incident report and that's it.