Otis Tyrone McKane said he was angry about a child custody fight and “lashed out at somebody who didn’t deserve it”.
McKane made the comments to reporters while being taken to Bexar County Jail in Texas and said he wished to apologise to the family of detective Benjamin Marconi.
Mr Marconi, 50, was reportedly shot and killed as he was giving someone a ticket for a traffic offence. He was sitting in his car at the time.
McKane, 31, said: “I’ve been through several custody battles, and I was upset at the situation I was in, and I lashed out at someone who didn’t deserve it.”
San Antonio Police Chief William McManus said: “I think the uniform was the target and the first person that happened along was the first person that (the suspect) targeted.”
The shooting was one of a number carried out against police officers in a number of states.
Other officers were shot in the states of Missouri and Florida, again while carrying out routine police tasks.
Police say there has been an alarming rise in the number of similar attacks.
Sixty officers, including the San Antonio detective, have been shot and killed while carrying out work duties this year, compared with 41 in all of 2015, according to the National Law Enforcement Officers Memorial Fund.
Of the 60 killed, 20 were purposely targeted, up from eight last year, the group said.
The shootings come less than five months after a black military veteran killed five white officers at a protest in Dallas.
Race was a factor in the Dallas attack, but police have not said if race played a part in any of the attacks on Sunday.