St. Louis avoided a season sweep after losing its first five meetings with the Phillies this year.
Alec Bohm homered for Philadelphia, which leads the NL wild-card race.
Walker homered off Seranthony Domínguez (4-5) with two outs to snap a 5-all tie.
John King (2-1) allowed one run in one inning for the win, and Ryan Helsley earned his 11th save in 15 opportunities.
Bohm launched a solo homer in the top of the eighth, and Nick Castellanos tied the score with an RBI single.
Goldschmidt had a two-run double in the third.
Cardinals starter Dakota Hudson, who went 4-1 in August, permitted three runs and five hits in five innings.
Philadelphia starter Taijuan Walker gave up five runs on eight hits over seven innings.
The series marked Philadelphia's first appearance in St. Louis since sweeping their wild-card series last year on the way to winning the National League pennant.
The Cardinals are 15-9 on Sundays this season, the only day they have a winning record.
Cardinals: OF Tyler O’Neill was placed on the 10-day injured list with a right foot sprain, and INF/OF Juan Yepez was recalled from Triple-A Memphis. Yepez is riding a 17-game hitting streak, the longest current run in the minors.
Philadelphia RHP Zack Wheeler (11-6, 3.70 ERA) is scheduled to face Braves RHP Kyle Wright (0-2, 7.48) in the opener of a three-game series Monday in Atlanta. Wheeler is 11-7 with a 3.24 ERA in 26 career starts against the Braves.
Cardinals RHP Adam Wainwright (4-11, 7.95 ERA) goes for his 200th career win when he faces Milwaukee RHP Freddy Peralta (12-8, 3.79) in the opener of a four-game series Monday in St. Louis. Wainwright is expected to retire after this season.
AP MLB: https://apnews.com/hub/MLB
Steve Overbey, The Associated Press