The youngest general on either side to be killed in the Civil War was John Herbert Kelly, who was born in March 1840 in Carrollton, Alabama. At the age of 17 he entered the United States Military Academy at West Point, and was on the verge of graduating in 1861 when he left following Alabama's secession from the Union. He joined the Confederate Army as a Second Lieutenant, and rose rapidly in rank, becoming the commanding officer of the 8th Arkansas Infantry Regiment in 1862, before being promoted to Brigadier-General in November 1863 at the age of 23. In September 1864, Kelly's Brigade was part of the Franklin-Nashville Campaign in Tennessee, when Kelly was shot in the chest by a Union Army sniper. Too badly wounded to move when the Confederate forces retreated, he was captured by Union forces on September 3, and died the following day at the age of 24.
https://en.wikipedia.org/wiki/John_H._Kelly
The youngest general on the Union side to die during the Civil War was James Birdseye McPherson, who was born in November 1828 in Clyde, Ohio, and graduated first in his class at West Point in 1853. By September 1862, he was a Brigadier-General on the staff of General Ulysses S. Grant, before, in March 1864 being appointed as commanding officer of the Army of the Tennessee. On July 22 1864, during the Atlanta campaign, McPherson was mortally wounded by a group of Confederate skirmishers and died at the age of 35.
https://en.wikipedia.org/wiki/James_B._McPherson