Taps has several different reported origins.
The following information from: www.snopes.com/music/songs/taps.asp

Legend:     It all began in 1862 during the Civil War, when Union Army Captain Robert Ellicombe was with his men near Harrison's Landing in Virginia. The Confederate Army was on the other side of the narrow strip of land.

During the night, Captain Ellicombe heard the moan of a soldier who lay mortally wounded on the field. Not knowing if it was a Union or Confederate soldier, the captain decided to risk his life and bring the stricken man back for medical attention.

Crawling on his stomach through the gunfire, the captain reached the stricken soldier and began pulling him toward his encampment. When the captain finally reached his own lines, he discovered it was actually a Confederate soldier, but the soldier was dead. The captain lit a lantern.

Suddenly, he caught his breath and went numb with shock. In the dim light, he saw the face of the soldier. It was his own son. The boy had been studying music in the South when the war broke out. Without telling his father, he had enlisted in the Confederate Army.

The following morning, heartbroken, the father asked permission of his superiors to give his son a full military burial despite his enemy status.

His request was partially granted. The captain had asked if he could have a group of Army band members play a funeral dirge for the son at the funeral.

That request was turned down since the soldier was a Confederate. Out of respect for the father, they did say they could give him only one musician.

The captain chose a bugler. He asked the bugler to play a series of musical notes he had found on a piece of paper in the pocket of his dead son's uniform. This wish was granted. This music was the haunting melody we now know as "Taps" that is used at all military funerals.

This is reported to be the true origin.

Origins:     It's hard to feel surprised when a melody as hauntingly beautiful as Taps picks up a legend about how it came to be written it's too mournfully direct a piece for the mere truth to suffice.

Taps was composed in July 1862 at Harrison's Landing in Virginia, but after that the fanciful e-mail quoted above parts way with reality. Day is done There was no dead son, Confederate or otherwise; no lone bugler sounding out the dead boy's last composition. How the call came into being was never anything more than one influential soldier deciding his unit could use a bugle call for particular occasions and setting about to come up with one.

If anyone can be said to have composed 'Taps,' it was Brig. Gen. Daniel Butterfield, Commander of the 3rd Brigade, 1st Division, V Army Corps, Army of the Potomac, during the American Civil War. Dissatisfied with the customary firing of three rifle volleys at the conclusion of burials during battle and also needing a method of ceremonially imparting meaning to the end of a soldier's day, he likely altered an older piece known as "Tattoo," a French bugle call used to signal "lights out," into the call we now know as 'Taps.' (Alternatively, he wrote the whole thing from scratch, a possibility not at all supported by his lack of musical background and ability.)

Whether he wrote it straight from the cuff or improvised something new by rearranging an older work, Butterfield brought 'Taps' into being. With the help of his bugler, Oliver W. Norton of Chicago, the concept was transformed into its present form. "Taps" was quickly taken up by both sides of the conflict, and within months was being sounded by buglers in both Union and Confederate forces.

Then as now, 'Taps' serves as a vital component in ceremonies honoring military dead. It is also understood by American servicemen as an end-of-day 'lights out' signal.

When "Taps" is played at a military funeral, it is customary to salute if in uniform, or place your hand over your heart if not.

Barbara "tap answer" Mikkelson

Another version.

Taps:     During a visit to Arlington National Cemetery, Va., you might hear the echoes of "Taps" being sounded by a bugler from one of the armed forces of the United States.

The 132-year-old bugle call was composed by Brig. Gen. Daniel Butterfield, who commanded the 3rd Brigade, 1st Division, V Army Corps, Army of the Potomac, during the American Civil War.

Butterfield wrote "Taps" at Harrison's Landing, Va., in July 1862 to replace the customary firing of three rifle volleys at the end of burials during battle. "Taps" also replaced "Tatoo," the French bugle call to signal "lights out." Butterfield's bugler, Oliver W. Norton of Chicago, was the first to sound the new call. Within months, "Taps" was sounded by buglers in both Union and Confederate forces.

"Taps" concludes nearly 15 military funerals conducted with honors each weekday at the Arlington National Cemetery as well as hundreds of others around the country. The tune is also played at many memorial services in Arlington's Memorial Amphitheater and at gravesites throughout the cemetery.

"Taps" is sounded during the 2,500 military wreath ceremonies conducted at the Tomb of the Unknowns every year, including the ones to be held this Memorial Day. The ceremonies are viewed by many groups, including veterans, schools, and foreign officials.

One of the final bugle calls of the day on military installations, "Taps" is played at 10 p.m. as a signal to service members that it is "lights out."

When "Taps" is played, it is customary to salute, if in uniform, or place your hand over your heart if not. The composer of "Taps" was born Oct. 31, 1831, in Utica, N.Y., and joined the Army in Washington, D.C.

He was awarded the Medal of Honor in the U.S. Volunteers on June 27, 1862. After his brigade lost more than 600 men in the Battle of Gaines Mill, Butterfield took up the colors of the 83rd Pennsylvania Volunteers. Under heavy enemy fire, he encouraged the depleted ranks to regroup and continue the battle.

Butterfield died July 17, 1901, and was buried at the U.S. Military Academy at West Point, N.Y. "Taps" was sounded at his funeral.

by Kathryn Shenkle

I am sure that there are other versions, so pick one for yourself.   But no matter which version of the origin you may choose to believe (if any) it is still a haunting tune and evokes deep emotions.