The White Sox trailed by two and had managed just one hit off of Collin McHugh (2-2) through the five innings before Dunn launched his soaring homer into the second deck in right field with one out in the sixth to put Chicago on top.
White Sox starter Jose Quintana (2-3) allowed two runs on seven hits in five innings for his first win since April 8.
Tyler Flowers had an RBI in the sixth and Gillaspie drove in two runs with a double in Chicago's three-run eighth inning.
Rookie George Springer and Jason Castro each had an RBI for the Astros. Chris Carter added a double and a single to extend his hitting streak to a season-high six games. He has improved in May after hitting just .153 in April.
McHugh allowed four runs on three hits, striking out seven in 5 1-3 innings for his second straight loss after starting the season 2-0.
Dunn, who was 0 for 11 before his home run, added a double in the ninth inning.
Jonathan Villar and Jose Altuve hit consecutive singles to start Houston's fifth inning and Villar advanced to third on an error by Dayan Viciedo on Altuve's hit. Villar scored on a groundout by Springer to put the Astros up 1-0.
Alejandro De Aza singled to start the third inning for Chicago's first hit and Moises Sierra walked with one out. McHugh then retired nine of the next 10 batters, with the only baserunner coming on a walk by Flowers with two outs in the fifth.
Gillaspie walked with one out in the sixth before McHugh plunked Jose Abreu. Dunn's sixth homer of the season came next to give Chicago the lead.
After the homer by Dunn, Viciedo doubled to chase McHugh. He was replaced by Josh Zeid, who intentionally walked De Aza with two outs before the RBI single by Flowers.
NOTES: The series continues Saturday when Houston's Jarred Cosart opposes Hector Noesi. ... Chicago manager Robin Ventura planned to give Abreu a day off to rest his sore left ankle. But Abreu didn't want to sit out so Ventura played him at designated hitter on Friday night.