Gallagher was found not-guilty this year of shooting civilians, murdering a captive Islamic State fighter, and threatening to kill his comrades during a 2017 deployment to Iraq; however, he was convicted of posing with a corpse for a photo.
The case has pitted the soldier's defenders, including US President Donald Trump and prominent Republicans, against parts of the top military brass who are seeking to rebuke Gallagher.
On Thursday, Trump said that he would not allow the Navy to remove Gallagher's ability to wear a Navy SEAL insignia known as the trident, which only members of the elite special operations force are allowed to bear.
Earlier this month, Trump restored Gallagher's rank after the Navy demoted him, along with clearing two other soldiers in unrelated war crimes cases.
The statement from the Pentagon on Sunday said that the call for Spencer's resignation came after the Pentagon learned that he had made a private proposal to the White House to restore Gallagher's ability to wear the trident.
Pentagon spokesman Jonathan Hoffman said Spencer's private proposal was in contrast to his public statements and that Esper had lost "trust and confidence" in him.
Spencer had publicly disagreed with Trump over the handling of Gallagher.
According to the New York Times, Spencer threatened to resign over the case, although Spencer denied that reporting.
"Unfortunately it has become apparent that in this respect, I no longer share the same understanding with the Commander in Chief [Trump] who appointed me, in regards to the key principle of good order and discipline," Spencer said in a letter sent to Trump on Sunday and carried in US media.
"I cannot in good conscience obey an order that I believe violates the sacred oath I took in the presence of my family, my flag and my faith to support and defend the Constitution of the United States," Spencer said.
In a series of tweets Trump said that he was "not pleased" with the Navy's trial of Gallagher and in a separate tangent said that "cost overruns" with military contractors were not adequately addressed.
Trump said he will nominate the current US ambassador to Norway Ken Braithwaite to take Spencer's spot.
Hoffman added that Esper supported disciplinary proceedings against Gallagher but "given the events of the last few days" Esper ended the the review of Gallagher's status and ordered that the soldier retire as a full Navy SEAL status.
"Secretary Spencer did the right thing and he should be proud of standing up to President Trump when he was wrong," Democratic Senator Chuck Schumer said in a statement calling the resigning Navy secretary "a patriot."
-------------------------------------------------------------------------------------------------------------