Goldschmidt drove a changeup from Joe Musgrove (7-9) for his 22nd home run, a solo shot that put St. Louis ahead 3-1 in the fourth. He has one homer in each of his past five games against Pittsburgh.
Kolten Wong homered later in the fourth and Dexter Fowler hit a two-run drive for a 6-1 margin in the fifth as the Cardinals won for the 11th time in 14 games since the All-Star break, including their last five. The Pirates have lost 11 of 13.
Miles Mikolas (7-10) gave up three runs and five hits in six innings.
Musgrove matched his season high by giving up six runs - five earned - and seven hits in five innings.
Jose Martinez hit an RBI single in the first and scored on Paul DeJong's sacrifice fly. Bryan Reynolds's sacrifice fly cut the Cardinals' lead to 2-1 in the third.