this has been explained at length elsewhere.
The point here is that Muhammad, may Allah bless him and grant him peace, was sent to both humankind and the jinn. Allah has stated in the Quran that the jinn listened to the Quran and believed in it, as He, Most High, says:
“And when We directed to you a group of jinn listening to the Quran, when they attended its recitation, they said, ‘Listen attentively.’”
The passage continues up to His words:
“Those are in clear error.”
He then commanded him to inform people of this, saying:
“Say, ‘It has been revealed to me that a group of jinn listened and said, “Indeed, we have heard a wondrous Quran.”’”
And so on. He commanded him to say this so that humans would learn about the circumstances of the jinn and know that he was sent to both humans and jinn. For this provides humans and jinn with guidance concerning their duty to believe in Allah, His messengers and the Last Day, their obligation to obey His messengers, and the prohibition of associating the jinn or anyone else with Allah. As He says in the surah:
“And there were men among humankind who sought refuge in men among the jinn, but they only increased them in transgression.”
A man would stop in a valley—valleys being places where jinn are likely to dwell, since they inhabit valleys more frequently than higher ground—and say, “I seek refuge in the great one of this valley from its foolish ones.” When the jinn saw that humans sought refuge in them, their transgression—and that of others—increased. This is why they respond to someone who adjures them or recites incantations using their names and the names of their kings: he adjures them by the names of those whom they revere