For example, if a US general lived on federal land, could they have owned a slave?
Yes, no, maybe, and I don't know are all technically correct answers. Let's dig into how.
Yes
From a simple, empirical perspective, slavery has been legal on federally-owned land in the United States. This is true both of federal property in enslaving states, like military forts, customs houses, arsenals, and mints and also of more traditionally-understood federal property like the territories or the District of Columbia. Washington City served as a significant market for humans to torture for profit for its entire history as the federal district up to late 1850 and continued to do so to a lesser degree for more than a decade thereafter. You could walk out of the Capitol, go down the street, and buy someone. Antislavery Americans viewed that as a bit of a national disgrace, but it's what happened.
You could do the same thing in an organized territory, by which I mean the ones that go on the maps in history books with an actual name and had some form of territorial government established by and for white men. Some territories had notional federal bans on introducing slavery, starting with the Northwest Territory (the future Ohio, Indiana, Illinois, Michigan, and a hunk of Minnesota), but that particular ban's history is muddled. The Northwest Ordinance both outlaws slavery and carries specific language singling out free inhabitants, implying the existence of enslaved ones. Those enslaved people did exist and their enslavers were very concerned that their enslaving be recognized as still valid, to the point of sending petitions and lobbyists back east on the matter. The feds took very little interest and the first territorial governor blandly told Washington, essentially as an afterthought, that he interpreted the NO's slavery ban as applying exclusively to bringing new enslaved people to the area. Whether or not that was the intent is a very murky question that I don't think we can settle to any degree of certainty with the record available to us.
The lesser-known companion to the Northwest Ordinance is the Southwest Ordinance, which applied to modern Tennessee. It's a copy and paste of the NO except for the slavery ban. So that's a fairly clear hard yes. In the absence of specific language prohibiting it, slavery is permitted to spread to all federal land. The use of that language is rare and generally applies to areas where slavery is not expected to spread to begin with or to areas that whites don't intend to colonize in the near future.
No
You can get a sense of how effective this is from the Northwest Ordinance above, but it's unfair to say that every slavery ban is a total paper tiger. By the 1820s, whites believe that slavery bans might actually be effective and seek to impose one upon Missouri. Missouri's enslavers both reject that suggestion and flagrantly thumb their nose at Washington by both keeping slavery around and including a ban on free blacks coming into the state that DC specifically forbade them from doing. They got away with it. The concession prize for the antislavery side was a pinky swear that future territory north of Missouri's southern border would come into the Union free.
An enslavery's pinky swear is exactly as binding as their commitment to emancipating people they personally own, as everyone found out in 1854 when the press was on to organize and open up modern Kansas to white colonization. Missouri's enslavers were deadset on preventing any white settlement of that land unless they could enslave there and forced through a repeal of the slavery ban. But between 1820 and then some territories were organized sans slavery in ways that appear to have mostly stuck. Illinois nearly voted slavery in right after statehood back in 1818 and kept an "apprenticeship" (read: enslaving) system for blacks until 1848, but Michigan, Wisconsin, and Minnesota didn't go in for those shenanigans. That didn't make them totally slavery free, since there were still grandfathered-in enslaved people from territorial days, but it's a bit farther in the right direction. To the best of my knowledge, Iowa Territory also never had any significant slavery going on. The Oregon Territory (the modern Pacific Northwest, more or less) and California were organized with slavery bans and while their efficacy is also dubious for the familiar reasons, they did not ultimately become solid enslaving states (CA was never a territory but its free status was something the feds assented to) or territories. Oregon did ban black people outright, though. So did Indiana and Illinois, but they actually had significant black populations already on hand and lacked adequate commitment to eliminationist white supremacy against blacks to make it stick.
Maybe?
So let's come to your question. Say an enslaver takes an enslaved person to a free jurisdiction. We can swing this a couple of ways, but let's do the simplest one first: it's straight up federal territory. Let's call it Wisconsin Territory, but the party presently in Minnesota. The enslaved person is Dred Scott and his enslaver is John Emerson, a doctor working for the Army. Scott would later argue that because Emerson took him willingly to a territory where slavery was banned per the Northwest Ordinance and by subsequent territorial laws that repeated the ban, chiefly the Wisconsin Enabling Act, that he was a free man. He sued for freedom on those grounds. By the prevailing legal custom, he ought to have had it. The Missouri courts noted as much themselves, but decided that this was just a courtesy states granted one another and they were not bound by it as any kind of precedent. Particularly since they now had to deal with these terrible abolitionists who thought enslaved people ought not be enslaved. Scott had every legal reason to believe he was in the right that his prolonged residence in a free jurisdiction, with his enslaver's knowledge and consent, granted him freedom.
Roger Taney didn't think so when the case reached the Supreme Court, going wildly beyond the case in an attempt to make a final settlement of the slavery question once and for all. In the course of that he also engaged in some staggeringly bad history that's largely beside the point, but has the benefit of telling you exactly what he -a Southern white man who had freed the people he personally had enslaved- thought was the only reasonable solution: No black person could be a citizen of the United States or have any rights a white man was bound to respect. On the actual facts of the case, more or less, Taney and the Court's majority held that the United States lacked the power to ban slavery from any federal territory because enslaved people were property and the Constitution protected property rights.
Taney's ruling is about the hardest yes one could want for slavery in the territories, so hard that it was a bit of a surprise. He could have easily ruled against Scott in a far narrower way had he wanted to, but he was out to settle the slavery question once and for all. Until then, things had run much more the way Scott and antislavery Americans expected. An enslaver might have the right to transit a free territory with a person they enslaved and even remain there for a bit (the right of sojourn) but those could be and generally were limited by state laws.
Which brings us around to your hypothetical general and the other situation: bringing an enslaved person into a jurisdiction where freedom is the rule but keeping them on federal land therein. That's another maybe. Most enslaved people traveling with enslavers in the military are going to be there as personal servants for officers. They would be handling domestic chores like the laundry, running errands, etc. That sort of thing is unlikely to keep them on the military reservation, since military posts in areas open to white colonization tends to sprout civilian towns. If an enslaver took someone up to a fort on the Canadian border, that person is probably in and out of free land all the time and the local laws might theoretically apply. Doing so is a significant risk, as Scott's case shows, and many enslavers wouldn't take it. I don't know of cases other than Scott's where that specific situation played out, but based on the general outline of things it's reasonable to think pre-Taney that they'd have as reasonable a claim to freedom as he did.
The reverse of this situation was a significant concern for the enslavers come the advent of the Republican Party. What happens if Lincoln declares he's not enforcing the Fugitive Slave Act on federal property? Suddenly every customs house and fort in the South is free land and enslaved people can set foot there, liberating themselves. That definitely was not the case beforehand, where regardless of the precise legal technicalities slavery definitely prevailed on the ground in the South.
To get beyond your question a bit, the real maybe hanging over the country in 1860 was not whether free territories were possible -Taney said no and it was questionable whether the GOP would be able to do anything about that until the opposition left town to run a treason- but rather whether free states would remain viable. The logic of Taney's ruling suggested otherwise and a case was making its way through the federal courts challenging the idea. Some enslaved people claimed freedom on being brought from Virginia to New York in transit to Texas. By New York law of the time, they were free and they sued accordingly. Their enslaver had handed the case over to the state of Virginia, which argued in effect for an indefinite right of sojourn and transit through free states. In other words, you could take enslaved people to a free state and keep enslaving them forever. At that point, how are those states free? But then Virginia got up to a different defense of slavery, treason, in 1861 and all that became moot.