Ive done it frequently. Of course the the base has to be largely defenseless for it to work, and the ship has to have enough life support to operate within its new range releative to the new owner, or it does have to plot a course back to its new territory, same as a player would have to.
Life support aside, You must be luckier than me then, i have never been able to get a gifted ship to attack a starbase! Oh sorry, once i had a gifted ship actually attack a starbase, when it returned an hour later!!
In galciv1 i used to send a fleet of constructors and a warship to an AI starbase, then i would surround the warship with the constructors and gift the warship to an AI at war with the starbase owner. The warship could then only escape by going through the starbase. This worked even for ships out of range!!! This does not work in DL, the ship will just sit there looking stupid, even if in supply range.
I'm afraid I can't let this slight to my knowledge of dodgy exploits go unchallenged. I just did this in one of my current games, with no real effort or setup, so I dont think luck has much to do with it. Of course, you can screw it up, by doing it when there's enemy ships close by that can kill the ship, or if it's too far out of range.
Here we go, playing as The Hive, I just parked one of my aging Mantis Cruisers next to a tasty terran econ mining base. Im just demonstrating the concept, so for now, imagine I parked a constructor there as well.

Now to talk to the Altarans. " Hey babe, what's up? Aww, don't be like that. Here's a ship for you, baby. By the way, I heard the terrans called you frigid. Now, it's not up to me, but I wouldn't take that if I were you..."

1 Turn later... "Oopsie!" Hey, look at the big fat economy resource just sitting there for my imaginary constructor to gobble up. Aww, too bad Terrans, but don't blame me. It was those filthy Altarians that did it. BTW, there are a bunch of altarian warships heading your way through my space, so i think you have more important things to be worrying about right now..."

Like I said, Ive done it often.