In a speech to the IOC a day before the opening of the games, Ban also reiterated his call for warring parties around the world to lay down their arms during the Olympics.
Ban said many professional athletes, gay and straight, are speaking out against prejudice and discrimination.
"We must all raise our voices against attacks on lesbian, gay, bisexual, transgender or intersex people," he said. "We must oppose the arrests, imprisonments and discriminatory restrictions they face."
Ban's remarks came at a time when activists and protesters have stepped up their campaign against Russia's law restricting gay rights activities.
Human Rights Watch posted a video this week on YouTube of gay people in Russia being bullied, chased and beaten, compiled from footage the group said was uploaded by perpetrators.
"Hatred of any kind must have no place in the 21st century," Ban said.
The U.N. chief noted that Principle 6 of the Olympic Charter enshrines the IOC's opposition to any form of discrimination.
"The Olympics show the power of sport to bring together individuals regardless of age, race, class, religion, ability, sex, sexual orientation or gender identity," Ban said.
Protesters in cities around the world targeted major Olympic sponsors Wednesday, urging them to speak out against the Russian law.
The law, signed in July by President Vladimir Putin, outlaws pro-gay "propaganda" that could be accessible to minors. Critics say it is so restrictive and vague that it deters almost any public expression of support for gay rights.
"I know that there has been some controversy over this issue," Ban told reporters after his speech. "At the same time, I appreciate President Putin for his assurance that there will be no discrimination whatsoever and the people with different sexual orientation are welcome to compete and enjoy this Olympic Games."
"I hope that this Olympics will be the venue where all the people, regardless of sexual orientation, LGBT and all of these people will really be able to enjoy the harmony and friendship, mutual respect and compete in the spirit of the Olympic movement," he added.
IOC President Thomas Bach has repeatedly said that Putin has given assurances that there will be no discrimination of any kind at the games.
"I can assure you the International Olympic Committee has undertook everything and we have all the assurances that the Olympic Charter will be fully applied in this Olympic Games, including the fundamentals of Principle 6, because this is what sport is standing for," Bach said to Ban.
"It is standing for respect and it is standing against any form of discrimination."
In his speech, Ban commended Putin for his "commitment to peace, unity and development through sport."
Ban's visit to Sochi comes after several world leaders decided to skip the games, including U.S. President Barack Obama, German President Joachim Gauck and French President Francois Hollande.
Ban reiterated his call for observance of an "Olympic Truce" during the Sochi Games.
"I repeat my call for all warring parties to lay down their weapons during the games - and to lift their sights to the promise of peace," he said.
Ban cited conflicts in Syria, South Sudan and the Central African Republic.
He said a truce "can enable life-saving humanitarian relief to reach suffering people and create an opening to lasting peace."
Athletes, he said, send a message that people and nations can put aside their differences.
"If they can do that in Sochi's sporting arenas, leaders of fighters should do the same in the world's combat areas," he said.
The U.N. General Assembly adopted a resolution in November calling for a global truce during the Olympics, which run until Feb. 23, and the Paralympics from March 7-16.
The resolution cites ancient Greece's traditional Olympic truce period that allowed free passage of athletes and spectators from often-warring city-states to the original games every four years.
The 193-member world body has passed resolutions since 1993 calling for an Olympic truce, but countries continue fighting wars whether the Olympics are on or not.
Follow Stephen Wilson on Twitter: http://twitter.com/stevewilsonap