The Holy Quran has explained this question already in Surah Shuraa. The Holy Quran tells us that there are poets who have no fixed direction, no purpose to follow. They are meandering into whatever direction their fancy takes them. And they neither belong here nor there. And these are the type of poets which Allah does not, the Holy Quran does not encourage.
It condemns this sort of poetry, a meaningless, meandering, verbal expression of something which has no reality. On the other hand, it says, There are those poets who believe in Allah and do good acts. When they express themselves in the form of poetry, they are exempted from that censure which has been mentioned before. That is the meaning of the Holy Verse.