"I don't like it. They're making too much money. Based on a shortage, they're making too much money," Trump told reporters at the White House.
High gas prices are a key political issue for Trump ahead of the midterm elections in November.
The average price of a gallon of regular gasoline in the United States has risen more than 37% since the start of the war, launched by Trump and Israel in late February.
The war has blocked the vital Strait of Hormuz and sent energy prices soaring.
US oil companies ExxonMobil and Chevron announced extraordinary profits on Friday, reflecting strong momentum stemming from the war in the Middle East.
ExxonMobil's second-quarter profits more than doubled to $14.5 billion, while Chevron's reached $12.1 billion, more than five times the level of the same quarter a year earlier.
Other major oil companies have also reported huge profits fueled by the conflict.
Trump, a staunch defender of fossil fuel interests, has railed against pump prices and in June announced he was directing the Justice Department to investigate any “speculation.”
Trump suggested to the oil companies that they find a solution as soon as possible. “They have to give some of that back to the public, and they better cut the retail price, the consumer price,” he said.