"They have forgotten that the Berlin Wall collapsed many years ago. Even if there are walls between nations, they must be removed," Rouhani said at a tourism convention in Tehran.
His remarks came after Trump ordered construction of a wall along the US-Mexico border and imposed tough new controls on travellers from seven Muslim countries, among them Iran.
Rouhani did not comment directly on the visa ban, but said Iran had "opened its doors" to foreign tourists since the signing of a nuclear agreement with world powers in 2015.
With more than a million Iranians living in the United States, many families are deeply concerned about the implications of Trump's visa ban, which also affects citizens from Iraq, Libya, Somalia, Sudan, Syria and Yemen.
On Thursday, one of Iran's most popular actresses said she would boycott next month's Academy Awards in protest at the ban.
Signup to our newsletter and follow us on Facebook and Twitter!
"Trump's visa ban for Iranians is racist. Whether this will include a cultural event or not, I won't attend the #AcademyAwards 2017," tweeted Taraneh Alidoosti, who stars in the Oscar-nominated "The Salesman".
No visas will be issued for migrants or visitors from the seven countries for at least 90 days, a restriction which can be extended if the countries in question do not provide extensive information on individuals seeking to enter the United States.
Quizzed on the street, many Iranians said they were baffled by the move.
"Americans themselves are mostly immigrants. To pick out a few countries and call them terrorist is not logical," said Mohsen Najari, a 33-year-old resident of the Iranian capital.
Tehran and Washington have not had diplomatic ties since students stormed the US embassy in 1980 following an Islamic revolution that toppled the US-backed shah.
"It's got nothing to do with terrorism. Iran and the US just don't have good ties. The US has good relations with Saudi Arabia so it doesn't matter how many terrorists come from Saudi Arabia," said Sima, a 27-year-old.