The result -- their first road win of the season -- against last season's Supporters Shield winners is a big stepping stone for NYCFC.
The Union played the majority of the match after going down a man early in the game.
NYCFC got on the board in the fifth minute on a tidy give-and-go. Outside the penalty area, Medina fed an overlapping Anton Tinnerholm, who drove into the Union's penalty area and played a ball across to Medina.
The forward left-footed a one-timed effort from eight yards out and past a helpless Andre Blake in goal.
Midway through the second half, NYCFC doubled the lead. A cross in the 65th minute from the left side by Iceland's Gudmundur Thorarinsson was popped into the air on a poor clearing header by Union defender Jack Elliott. Fellow center-back Jakob Glesnes then attempted to play it with his chest back to Blake.
Castellanos intercepted the pass and finished cheekily with a backheel for his third goal in as many starts this season.
In the 16th minute, the Union went down a man when midfielder Jose Martinez took down Castellanos near midfield and was initially given a yellow card. After a review of the incident, Martinez was given a red card for elbowing Castellanos repeatedly, including a blow to the head.
The Union did not rotate their lineup as heavily as expected, fielding eight of the same starters as beat Atlanta United 3-0 on Tuesday night in the first leg of the quarterfinals of the CONCACAF Champions League.
Not surprisingly, the shorthanded Union produced little in the way of offense. They held possession for just 33 percent of the match and mustered just four shots, none on goal against goalie Sean Johnson.