Green Eggs and Ham was written when he was challenged. Someone (now, I don't remember who) said he could not write a book with a limited number of words in it. He did and it was one of his best sellers!
He got his ideas from some of the books that he has read before, which gave him small hints of what to write about. He also gathered ideas from the authors of the books he read, including the challenges they faced.