The origin is from the use of percussion caps or gun caps, a piece of copper used for igniting the powder in guns.
The first use in the OED is from around 1826:
c1826 Wellington in Mem. R. Davenport-Hill 231 ‘Croker, you may understand the battle of Waterloo, but I'll be d——d if you know anything of copper caps!’
Bursted a cap
The OED has burst a cap from 1838, which you can read in context here:
While standing a few paces from each other, Lafayette came up, and remarked to the Col., ' If you spill my brother's blood, I will spill yours,' about which time Chamberlayne's pistol fired, and immediately Lafayette bursted a cap at him.
Another early example can be found in the Extra Globe from 1839:
On the 22nd instant about forty half and full blood Cherokee Indians came to the house of John Ridge, esq. a distinguished Cherokee, and just about daylight entered the chamber of Mr. Ridge unperceived by any of the family, and bursted a cap at his head, which awoke him, who then saw and felt his impending fate, no doubt, and called on his assailants for mercy.
The verb bursting was used in the technical literature of firearms. For example, in Newton's London journal of arts and sciences (1837) has details on William Westley Richards "invention of certain improvements in primers for discharging firearms by means of percussion". Here's a description of figure 16:
The percussion or detonating powder being removed from the top of the cap into its novel position nearer to the mouth thereof a is the top of the cap b the sides c the position of the priming or detonating powder the dotted lines as before showing the direction of the force of explosion whereby it will be seen that the metal cap case or shell will be opened and distended only in a small degree and not likely to be burst to pieces as in the former the space between a and c being occupied by a piece of any kind of hard metal d soldered or otherwise fastened into the cap.
It seems to have been quite common in the late 19th century in books about the American Civil War and later in cowboy stories. It can be found in some court reports.
The Concise New Partridge Dictionary of Slang (2007) gives:
bust a cap 1 to shoot a gun US 1965
Cop Talk: A Dictionary of Police Slang (2000) shows a variant:
to cap—“to shoot,” as in “bust a cap in his black ass.”—Susanna Moore, In the Cut .
Law enforcement vocabulary (1973):
Bust a Cap. Juvenile slang: Shoot a gun
Two early uses in AAVE are in Henry Williamson's autobiography Hustler! (1965), edited by R. Lincoln Kaiser:
He kept tellin' me, "I shoot you, boy! I'll bust a cap in your ass !" I said, "A ww man, let me go up and talk to my mother!" and I was steady pullin' him toward the door. He stopped and pointed his gun! I said to myself, "That mother fucker ain't goin' a shoot me, 'cause he ain't got ...
"Willie said, "You get that money you mother fucker! If don't I'm goin' a bust a cap in your ass!" So Buddy asked this pimp for the money.
A possible AAVE use can be found in John Oliver Killens' first novel Youngblood (1956), "dealing with a fictional black Georgia family in the early 1900s":
"They look like a couple of peckerwoods to me."
Elwood Dailey sat on the side of a ditch and he looked long and hard down the barrel of his rifle, "I got em covered, Ray. Should I bust a cap in they asses, somebody?" "Naw, wait a minute, Ellie. Wait till they get up here. I just want to find out how crazy a cracker can be. Coming out here amongst a whole bunch of evil colored folks all by their lonesome. Let's see what they got to say for they self."
Still I Rise: A Graphic History of African Americans (2009) by Roland and Taneshia Nash Laird suggests it entered AAVE around the 1950s:
To her credit, Robbins also unearthed the work of a second black woman cartoonist of the 1950s, Doris McClarty, whose one-page strip "Fireball Freddie" appeared in the black magazine Hep. Its characters, slang-spouting hipsters, seemed drawn from the world of Cab Calloway. ("Well Pops," says one, "Kate gave me the gate. Now I'm doing the town brown.") However, students of the genre may find McClarty's work less interesting for its draftsmanship or ideas than for its linguistic curiosities — the discovery, for example, that black argot like "bust a cap" and "cop a plea" dates from the 1950s.
The comic was published in the October 1955 issue of Hep Magazine, and here's the comic itself, courtesy of the Ladies Making Comics blog.