Spanish claims to “Florida” ran all the way to the Mississippi. After the 7 years war the UK gained control over all of Florida. And in 1763 they split Florida into two separate territories: East Florida which included the peninsula, West Florida which included everything between the Mississippi and the Chattahoochee Rivers and everything south of 32° 22′ N (basically the line of I-20/US-80 between Vicksburg-Jackson-Selma-Montgomery-Tuskegee-Columbia). Wiki has a pretty good map of British West Florida. So British West Florida included not just the Florida panhandle but parts of Louisiana and the Southern parts of modern Mississippi and Alabama.
After the American Revolution the border in this area was disputed. Florida had been granted by treaty to Spain, without specifying the borders. Spain’s position was that meant the Northern border was 32° 22′ N. However in the treaty with the newly formed US the border was specified as 31° N. It took until 1796 for Spain and the US to come to an agreement on 31° N as the border between Georgia and West Florida, but that still left the entirety of the Gulf Coast in Spain’s hands as West Florida. Within a few years the whole area south of Tennessee was ceded by Georgia and became the Mississippi Territory.
The area almost immediately came into dispute with again though. When the US bought Louisiana it’s borders weren’t exactly well defined, especially on either side of the mouth of the Mississippi. The US claimed that everything West of the Perdido River was part of Louisiana and thus belonged to them. As an editorial aside this was a fairly ridiculous claim. Neither the French nor the Spanish ever viewed Louisiana as extending along the Gulf Coast that way, and the Americans had zero justification for the claim, other than it’d be really nice to have. The Spanish claimed their traditional borders continued to extend to the Mississippi River.
The deciding factor though, was that over the decades after the American Revolution the bulk of settlers in West Florida had been Anglos and Americans. Fed up with the pace of negotiations and generally not wanting to be Spanish in 1810 West Florida broke into revolt. Although it’d be a mistske to say it was solely an American vs Spanish rebellion. There were also French partisans and Tory partisans who wanted the area to return to France or Britain, and those who wanted an independent state rather than be par of any of the four powers. There was a short lived Republic of West Florida, but James Madison used the crisis to occupy everything West of Mobile Bay under the pretense of reestablishing order within the parts of West Florida claimed by the US.
In 1812 Louisiana was made a state and the parts of West Florida occupied in 1810 were assigned to the State of Louisiana and the Mississippi Territory. In 1817 the territory was split into Mississippi and Alabama under their current borders. But all of this was done with Spain still claiming control over everything on the coast to Baton Rogue, and actually controlling everything East of Mobile Bay. The borders of Alabama were established while Spain still controlled all of modern Florida.
The Gulf area borders were finally settled in 1819 in the Adams-Onís Treaty in which (among many other things) Spain sold all its Florida claims to the US in both West and East Florida. The US would take control of the parts it hadn’t siezed in 1821. But Alabama was made a state in 1819, before the rest of West Florida was added to the US. And so West Florida was just rolled back into East Florida.
So to sum up. The current Alabama-Florida border is defined by where the de facto international border between the US and Spain was at the time Alabama became a territory and then a state.