Question: how did jafar know about the lamp?
Answer: In the film, we see that he and Iago had a secret lair underneath the Sultan's palace. He must had used that secret lair to find out about the Genie's lamp and where it was located at. And after that, he knew everything about the lamp.