Praise be to Allah.
Firstly: the ruling on writing fictional stories.
In the answer to question no. 174829, we discussed the scholarly views on writing fictional stories, and said that it is most likely that it is permissible to do that, if the story has a message and calls to good and righteousness.
For more information, please see the answer to question no. 278767.
Secondly: using verses and hadiths in fictional stories
With regard to using texts from the Qur’an and Sunnah in these stories, if they are quoted in a proper manner and in the right context, it does not seem that there is any reason to disallow that.
Some of the verses of the Qur’an and hadiths are very clear, and a person does not need a great deal of knowledge to understand their meanings; rather anyone who reads them can – usually – understand them, such as the verses which enjoin obligatory duties such as prayer, zakaah, Hajj and fasting, and the verses and hadiths which enjoin good attitudes and manners, and forbid their opposites – and so on.
So there is nothing wrong with the writer quoting them, because their meanings are clear, and there is no ambiguity in them.
And there are other verses and hadiths which need a person of knowledge in order to understand their meanings. In that case, what must be done is to research their meanings or ask people of knowledge, and it is not permissible for one who does not understand their meanings to quote them, because he may misquote them and misinterpret them.
It was narrated from Ibn ‘Abbaas (may Allah be pleased with him) that he said that the verses of the Qur’an are of four types with regard to their interpretation (tafseer). He said that the verses of the Qur’an are of four types: one type that the Arabs understand on the basis of their language; one type that no one has any excuse for not knowing the meaning; one type that scholars understand; and one type that only Allah knows, and whoever claims to have knowledge of it is lying.
Narrated by Ibn Jareer in the Introduction to his Tafseer (1/70, 73). Also quoted by Ibn Katheer in the Introduction to his Tafseer (1/14).
Az-Zarkashi said in al-Burhaan (2/164-167): This is a sound categorization.
As for that which the Arabs know and understand on the basis of their language; it is the matter of language and grammar…
Whatever tafseer is of this type, the way of the mufassir is to accept what was narrated about the language of the Arabs, and one who does not have knowledge of the language and the way things are expressed in it does not have the right to interpret anything of the holy Book; in his case it is not sufficient to have a little knowledge of the Arabic language, for a phrase may have two meanings of which he only knows one.
The second matter is that which no one has any excuse for not knowing. This is what is readily understood of texts that speak of the rulings of Islam and proofs of Tawheed, and every phrase that has one clear meaning and no other, and he knows that this is the meaning intended by Allah (may He be exalted). With regard to this category there is no difference of scholarly opinion concerning the ruling and there is no confusion about how to interpret it, for everyone understands the meaning of Tawheed from the verse in which Allah (may He be exalted) says (interpretation of the meaning): “So know, [O Muhammad], that there is no deity except Allah” [Muhammad 47:19], and that He has no partner in His divinity.
Everyone inevitably knows that what is meant by the verse “And establish prayer and give zakah” [al-Baqarah 2:43], and similar verses that speak of commands, is that prayer and zakaah are obligatory.
The third matter is that which no one knows except Allah (may He be exalted). This refers to texts that speak of unseen matters, such as the verses which speak of the onset of the Hour, the sending down of rain, what is in the wombs and the nature of the soul.
The fourth matter is that which is subject to the understanding of the scholars and their ijtihaad. This is what is usually called ta’weel (interpretation), which explains what the meaning of the text boils down to. This refers to the derivation of rulings, explaining what is mentioned in brief, discussing the specific meaning of what is mentioned in general terms, and explaining every phrase that may have two or more meanings. These are the texts concerning which it is not permissible for anyone except scholars to engage in ijtihaad. End quote.
And Allah knows best.