According to the sources, after Cain killed his brother Abel; He fled to Yemen being afraid of his father, Adam (PUH). Satan told him “Abel’s sacrifice was burnt by the fire and accepted. Because He worshipped and served the fire.” Then the Satan inspired him to do the same.
Thus Cain built a fire house, started a fire there, and worshipped it. (History of Tabari v.1, p.82)
At first, Sons of Seth (PUH) would come to visit Adam’s grave in a cave in a mountain. They would show respect to him and
would pray Allah to grant him mercy.
One man from the sons of Cain said:
‘O sons of Cain! The sons of Seth are turning around Adam’s grave and showing respect to him. Whereas you don’t have anything like this!’ Then he carved an idol for them. He was the first man who made an idol in the history. (Ebulmunzir Hisham, Kitabu’l-Asnam, p.50-51, Yakut Mucemülbüldan v.5, p.367)
In another resource, it is said that the first idol was made in the time of Prophet Enoch (PUH).