Castellanos scored in the 20th minute and converted a penalty kick in first-half stoppage time to send NYCFC (9-5-4, 31 points) to their sixth consecutive home win. The club has outscored the opposition by a 15-2 margin during that stretch.
Castellanos has five goals and three assists in his last five matches overall, including a tally in NYCFC's loss to Pumas UNAM in Leagues Cup action on Wednesday.
Maximiliano Moralez notched an assist and Sean Johnson made four saves for NYCFC, who have collected at least a point in six straight MLS matches overall (4-0-2).
Nick Marsman finished with one save for Inter Miami (4-9-4, 16 points), who failed to take advantage of seven corner kicks en route to seeing their franchise-best unbeaten streak end at four matches (2-0-2).
NYCFC opened the scoring after Moralez's left-footed cross found Castellanos, who provided the finish with a header that sailed inside the right post. Moralez's sixth assist pulled him into a tie with Castellanos for the club lead.
NYCFC doubled the advantage just before halftime, with an unintentional assist coming after a hand ball in the penalty area from Inter Miami's Kelvin Leerdam. Castellanos made Miami pay for its miscue after chipping a right-footed shot past a diving Marsman.
Castellanos' bid for the hat trick was denied in the 74th minute, with Marsman making the save on his header from the center of the box.
Miami's nearly opened the scoring in the 12th minute, however Lewis Morgan's left-footed shot from outside the box was denied by Johnson.