The Cuban was dropped twice and eventually retired in seven rounds against Castellanos at lightweight back in May and had mulled over a possible move back down in weight.
Campaigning once again at lightweight, Gamboa squeezed through against Alexis Reyes by the smallest of margins at the Oasis Arena in Cancun, Mexico.
Ten completed rounds of action, in which Gamboa only displayed glimpses of his obvious brilliance, saw the 35 year-old come out on top 95-94 (twice) on the scorecards.
A third judge carded even at 94 apiece as Gamboa moved to 27-2 and closer to yet another world title shot.
Also on the bill, Alejandra Jimenez retained her undefeated record along with her WBC heavyweight title with a third round stoppage of Vanessa Joanisse.
Jimenez proved to be too much to handle for the inexperienced Joanisse as the Mexican made it seven knockouts from nine wins.
In the headliner, Francisco Rodriguez inflicted a maiden loss on Elias Joaquinho as the ex-world title holder scored a seventh round victory.
Now campaigning at flyweight, the one-time minimumweight ruler ended the contest 25 seconds from the end of the session.