5:25 PM PT -- TMZ has just obtained a demand letter written by Meek's lawyer, Joe Tacopina, to the Cosmopolitan. Tacopina writes, "... we have learned that the Cosmopolitan maintains a list of African American recording artists who should be denied access for no other reason than than their culture and skin color. Such course of conduct constitutes discrimination per se, in violation of state and federal law, and exposes you to significant monetary damages."

The letter goes on -- "...we urge you to promptly issue an apology to Mr. Williams and grant him immediate access. In the event you fail to heed this one and only warning, we intend to pursue all legal recourse against you."

Meek Mill was just told to get the hell away from the Cosmopolitan Hotel and Casino in Las Vegas -- and that if he didn't leave ... he'd be arrested and locked up.

The Philly rapper and 2 members of his security rolled up to the Cosmo at around 3:30 PM PT Saturday when they were stopped by security. You see in this video ... security was not about to let Meek inside the hotel.

Our sources say Meek asked the guard why he couldn't come in, saying he didn't do anything untoward in the past -- he had only been there once before, with Nicki Minaj for a Jay-Z event 5 years ago.

Security made it clear ... if Meek got out of the car, he'd be arrested. Meek, who was there to see a DJ Mustard show, continued to ask why he was being denied, but the guard said, "I don't know why."

Meek's lawyer, Joe Tacopina, tells TMZ, the head of security made it clear -- the decision to ban Meek came from above ... the security chief said, "This comes from way higher up than me."

Tacopina says he spoke with someone whom he says is "a well-placed person inside the hotel" ... whom Tacopina says told him a group of hotels have tried to keep rappers out of the hotels. Tacopina claims it's racially motivated, saying, "They wouldn't ban Vanilla Ice."

Meek himself addressed the altercation on social media, writing in part ... "Cosmopolitan hotel/casino going to extreme racist levels to keep too many black entertainers and black people .... they said they gone lock me up."

He added, "Some of these casinos have a bunch of Tatics to keep the level of blacks down .... but love to take our money!!!! This happens to a lot of black entertainers not just me either!!"

We've reached out to the Cosmopolitan for clarification on why Meek was denied entry ... so far, no word back.