A D.C. police detective shot himself in the jaw in a second-floor lavatory at District police headquarters yesterday when his service revolver discharged in what an official called a "terrible fluke."

Detective James W. Henderson of the department's check and fraud unit was shot in a lavatory about 100 feet from the 300 Indiana Ave. NW entrance to the building, police said. They said it was the third time an officer had accidentally shot himself inside a police building in less than four weeks.

Henderson, 38, was in fair condition last night at George Washington University Medical Center, according to a hospital spokeswoman. She said the bullet entered Henderson's jaw about an inch in front of the right ear and exited at the back of the neck.

A police official said the shooting occurred about 7:15 a.m. after Henderson, a 15-year veteran of the police department, apparently removed his service revolver and hung it by the trigger guard on a coat hook inside one of the two swinging doors to a stall.

As Henderson was standing in the stall with the doors open, he apparently leaned against the door on which the gun was hanging. His weight caused the handle of the gun to hit the side wall of the stall and the gun discharged, the official said. Sources said that two other persons who were elsewhere in the lavatory were not injured.

"During our recruitment training at the police academy and during our semiannual firearms qualification, members are instructed how to properly safeguard their service revolvers while in the locker room facilities," an official said. He said the incident is being investigated.

Three officers have accidentally shot themselves since Oct. 29, when an officer in the 3rd District cell block shot himself in the right foot while removing his revolver from his pant pocket, according to police sources. On Nov. 17, an officer shot himself in the foot while cleaning his gun in the 5th District locker room, the sources said.

Since January, there have been seven accidental or unintentional discharges of D.C. police service revolvers, four of which resulted in injury, an official said.

Two officers accidentally fired their service revolvers in fiscal year 1985, which ended Sept. 30, and one in fiscal year 1984, police said. It was unclear yesterday if any of those officers were injured.