This slang has been used in numerous songs by rap artist, especially Drill Rappers from Chicago. In Chief Keef's Macaroni time, he said "Dumb f*ck just popped a flat, I'm beamin' right now", Chief Keef is basically saying he just took a pill and he's really high. In SD's "Can't Tell Me Sh*t" song, Fredo Santana said "I need a pill SD where dem' flats at".
Some people also refer to Xanax pills as flats because they actually look flat. Some people actually refer to any pharmaceutical pills they can get high off as "Flats" if they have a flat surface. Though some people refer to Xanax pills as flats, majority of people talking about flats are talking about ecstasy pills.