Like if you had two planets that had a close orbital path could the moon be pulled away from the first planet?
Given the nature of 3 body orbital mechanics, it's possible, just unlikely and I hope you'll forgive me if I skip the math.
In our solar-system, it's pretty much not possible because our planets are too far from each other. Speaking in solar-system distances, Moons have to be close to planets, within the stable regions of their planet's hill spheres in order to have long-lasting orbits.
I'm going to assume that I can ignore temporary moons, which in my opinion, aren't real moons anyway.
The difficulty with one planet giving another planet it's moon is that they'd have to pass quite close to each other, and one of the definitions of planets is that they have their own orbital region around their star, but orbits can move over time, so it's possible for two planets to pass close to each other but there would be other effects as well because, as they got close, the planets would interfere with each other as well.
In a just right scenario a moon could theoretically be passed from one planet to another during a close pass. This is similar to the theory about how an asteroid in a binary-asteroid pair could get captured if it passes close to a planet.
A planet could also lose a moon and maybe in a few million years that moon could find it's way to being captured by another planet, but I don't think that's what you're asking.
You might think that around a red-dwarf where planets are quite close to each other and much closer to their star, that a transfer could happen due to proximity, but the difficulty there is that planets that close to their star have a hard time having moons at all because they have very short Hill radii. It's probably more likely, but still unlikely, to happen between two distant planets.
Take the planet Neptune, as an example. Neptune has a Hill radius of a bit over 100 million km, about the distance between Venus and the Sun, and it's true region of stability, between 33% and 50% of that, so Neptune could in theory have a moon in a stable orbit as distant as perhaps up to 50 million km. At that distance, it's moon would orbit it very slowly, about .37 km/s with an orbital period of about 25 years.
(A fun mathematical quirk, which has nothing to do with your question, but if you calculate the maximum orbital period a moon can have inside the stable orbital region around it's planet, it works out to about 1/6th the period the planet has around it's star, it doesn't matter the mass of the planet or the distance to the star that 1/6th rule roughly applies to every scenario).
So in theory, if Uranus passed close to Neptune, say within 100 million km, the theoretical distant moon, especially if it had a somewhat elliptical orbit, could get transferred from Neptune to Uranus and as is passed. In the process, it would become a wrong-way moon around it's new planet. (insert wacky theory about Triton having once orbited Uranus here).
Uranus and Neptune never get that close, though perhaps they did when our solar-system was young and Jupiter was migrating.
It's more likely, if two planets got that close that they'd alter each other's orbits rather than trade a moon. The moon could also be ejected from one planet and not captured by the other. That's probably a more likely scenario. If one of the planets was considerably smaller than the other, the entire planet could be tossed around significantly, perhaps tossed out of the solar-system.
What probably does happen, is binary systems like Pluto-Charon, when they pass close enough to a planet, one of them can be captured. This article suggests that Triton, Neptune's wrong way moon, was captured by that method. A capture involving 3 gravitational bodies isn't that strange, but the criteria that two of those bodies are planets makes it more rare.
3 body orbits allow for a variety of scenarios, and trading a moon is probably one of the least likely options but theoretically possible. This just might happen when solar systems are young and chaotic and full of planetesimals.
On a related note, I've read an article a while back that stars in the center of our galaxy can trade planets, but I looked, I couldn't find that article.
For this to happen randomly? That would be nearly impossible. I'm guessing it would be possible to construct a situation where this could be accomplished for an object under some control (like a spacecraft with minimal thrust).
But if the situation isn't precisely controlled, it is much more likely that during any interaction the satellite will either be driven closer to the first planet or that it will be ejected away from both planets (probably to a solar orbit, becoming a planetoid).
It's hard enough for a random object to get captured by a planet. To do so immediately from orbiting a nearby planet makes the odds near zero. Also two planets (each large enough to capture a moon) on close orbital paths would be unstable.
It's quite possible for (small) satellites to move from one planet to another. Just there would normally be a long period in between when it's not orbiting either one.